Article View: borland.public.cppbuilder.nativeapi
Article #14998Re: system CDM
From: Ed Mulroy [TeamB]
Date: Fri, 25 Jul 2003 19:53
Date: Fri, 25 Jul 2003 19:53
91 lines
3436 bytes
3436 bytes
Nothing you show needs a call to the function system. All of them can
easily be done in your program. You do a directory with FindFirstFile,
FindNextFile and FindClose and writing the results to the screen. You do a
pause by writing a prompt and waiting for a key to be pressed. Look in the
Windows help file for docs on those functions, win32.hlp
For an example of what I am saying, build this as a console mode program and
run it:
----------------------------
#include <windows.h>
#include <stdio.h>
#include <conio.h>
void DoDir()
{
WIN32_FIND_DATA wfd;
HANDLE find_handle;
find_handle = FindFirstFile("*.*", &wfd);
if (find_handle != INVALID_HANDLE_VALUE)
{
char current_dir[MAX_PATH + 1];
int num_files = 0;
int num_dirs = 0;
unsigned long size_sum = 0;
GetCurrentDirectory(sizeof(current_dir), current_dir);
printf("Directory of %s\n\n", current_dir);
do
{
FILETIME ft;
SYSTEMTIME st;
FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &ft);
FileTimeToSystemTime(&ft, &st);
printf("%02u/%02u/%04u %02u:%02u %s ",
st.wMonth, st.wDay, st.wYear,
st.wHour % 12, st.wMinute,
(st.wHour >= 12) ? "PM" : "AM");
char *filename = wfd.cFileName;
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
++num_dirs;
printf("%-15s%s\n", "<DIR>", filename);
}
else
{
++num_files;
size_sum += wfd.nFileSizeLow;
printf("%6s%8u %s\n", " ", wfd.nFileSizeLow, filename);
}
} while (FindNextFile(find_handle, &wfd));
FindClose(find_handle);
printf("%16d File(s) %13u bytes\n", num_files, size_sum);
printf("%16d Dir(s)\n", num_dirs);
}
}
void DoPause()
{
printf("Press any key to continue . . . ");
if (!getch())
getch();
}
int main()
{
DoDir();
DoPause();
return 0;
}
----------------------------
. Ed
> Stephane Baillargeon wrote in message
> news:3f216b4f$1@newsgroups.borland.com...
> How can I execute multiple commands in one and only
> one cmd window without using a batch file. Is it possible?
>
> example:
> system ( "dir" );
> system ( "pause" );
Technical Details
Message-ID:
<3f218ac9@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!priapus.visi.com!news-out.visi.com!petbe.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3f216b4f$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,aec67fd76b7834fc X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-07-25 13:12:02 PST From: "Ed Mulroy [TeamB]" <ed@mulroyREMOVETHESECHARS.org> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f216b4f$1@newsgroups.borland.com> Subject: Re: system CDM Date: Fri, 25 Jul 2003 15:53:38 -0400 Lines: 93 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 209.170.133.171 Message-ID: <3f218ac9@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1059162825 209.170.133.171 (25 Jul 2003 12:53:45 -0700) X-Authenticated-User: edmulroy Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!priapus.visi.com!news-out.visi.com!petbe.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail