2001-02-28 22:33:23 +00:00
|
|
|
/* $Id: dir.c,v 1.10 2001/02/28 22:33:23 ekohl Exp $
|
1999-12-15 00:50:41 +00:00
|
|
|
*
|
1999-03-20 20:28:42 +00:00
|
|
|
* DIR.C - dir internal command.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* History:
|
|
|
|
*
|
|
|
|
* 01/29/97 (Tim Norman)
|
|
|
|
* started.
|
|
|
|
*
|
|
|
|
* 06/13/97 (Tim Norman)
|
|
|
|
* Fixed code.
|
|
|
|
*
|
|
|
|
* 07/12/97 (Tim Norman)
|
|
|
|
* Fixed bug that caused the root directory to be unlistable
|
|
|
|
*
|
|
|
|
* 07/12/97 (Marc Desrochers)
|
|
|
|
* Changed to use maxx, maxy instead of findxy()
|
|
|
|
*
|
|
|
|
* 06/08/98 (Rob Lake)
|
|
|
|
* Added compatibility for /w in dir
|
|
|
|
*
|
|
|
|
* 06/09/98 (Rob Lake)
|
|
|
|
* Compatibility for dir/s started
|
|
|
|
* Tested that program finds directories off root fine
|
|
|
|
*
|
|
|
|
* 06/10/98 (Rob Lake)
|
|
|
|
* do_recurse saves the cwd and also stores it in Root
|
|
|
|
* build_tree adds the cwd to the beginning of its' entries
|
|
|
|
* Program runs fine, added print_tree -- works fine.. as EXE,
|
|
|
|
* program won't work properly as COM.
|
|
|
|
*
|
|
|
|
* 06/11/98 (Rob Lake)
|
|
|
|
* Found problem that caused COM not to work
|
|
|
|
*
|
|
|
|
* 06/12/98 (Rob Lake)
|
|
|
|
* debugged...
|
|
|
|
* added free mem routine
|
|
|
|
*
|
|
|
|
* 06/13/98 (Rob Lake)
|
|
|
|
* debugged the free mem routine
|
|
|
|
* debugged whole thing some more
|
|
|
|
* Notes:
|
|
|
|
* ReadDir stores Root name and _Read_Dir does the hard work
|
|
|
|
* PrintDir prints Root and _Print_Dir does the hard work
|
|
|
|
* KillDir kills Root _after_ _Kill_Dir does the hard work
|
|
|
|
* Integrated program into DIR.C(this file) and made some same
|
|
|
|
* changes throughout
|
|
|
|
*
|
|
|
|
* 06/14/98 (Rob Lake)
|
|
|
|
* Cleaned up code a bit, added comments
|
|
|
|
*
|
|
|
|
* 06/16/98 (Rob Lake)
|
|
|
|
* Added error checking to my previously added routines
|
|
|
|
*
|
|
|
|
* 06/17/98 (Rob Lake)
|
|
|
|
* Rewrote recursive functions, again! Most other recursive
|
|
|
|
* functions are now obsolete -- ReadDir, PrintDir, _Print_Dir,
|
|
|
|
* KillDir and _Kill_Dir. do_recurse does what PrintDir did
|
|
|
|
* and _Read_Dir did what it did before along with what _Print_Dir
|
|
|
|
* did. Makes /s a lot faster!
|
|
|
|
* Reports 2 more files/dirs that MS-DOS actually reports
|
|
|
|
* when used in root directory(is this because dir defaults
|
|
|
|
* to look for read only files?)
|
|
|
|
* Added support for /b, /a and /l
|
|
|
|
* Made error message similar to DOS error messages
|
|
|
|
* Added help screen
|
|
|
|
*
|
|
|
|
* 06/20/98 (Rob Lake)
|
|
|
|
* Added check for /-(switch) to turn off previously defined
|
|
|
|
* switches.
|
|
|
|
* Added ability to check for DIRCMD in environment and
|
|
|
|
* process it
|
|
|
|
*
|
|
|
|
* 06/21/98 (Rob Lake)
|
|
|
|
* Fixed up /B
|
|
|
|
* Now can dir *.ext/X, no spaces!
|
|
|
|
*
|
|
|
|
* 06/29/98 (Rob Lake)
|
|
|
|
* error message now found in command.h
|
|
|
|
*
|
|
|
|
* 07/08/1998 (John P. Price)
|
|
|
|
* removed extra returns; closer to MSDOS
|
|
|
|
* fixed wide display so that an extra return is not displayed
|
|
|
|
* when there is five filenames in the last line.
|
|
|
|
*
|
|
|
|
* 07/12/98 (Rob Lake)
|
|
|
|
* Changed error messages
|
|
|
|
*
|
|
|
|
* 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
|
|
|
|
* added config.h include
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 04-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
|
|
|
|
* Converted source code to Win32, except recursive dir ("dir /s").
|
|
|
|
*
|
|
|
|
* 10-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
|
|
|
|
* Fixed recursive dir ("dir /s").
|
|
|
|
*
|
|
|
|
* 14-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
|
|
|
|
* Converted to Win32 directory functions and
|
|
|
|
* fixed some output bugs. There are still some more ;)
|
|
|
|
*
|
|
|
|
* 10-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
|
|
|
|
* Added "/N" and "/4" options, "/O" is a dummy.
|
|
|
|
* Added locale support.
|
|
|
|
*
|
|
|
|
* 20-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
|
|
|
|
* Redirection safe!
|
1999-03-21 21:32:45 +00:00
|
|
|
*
|
|
|
|
* 01-Mar-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
|
|
|
|
* Replaced all runtime io functions by their Win32 counterparts.
|
2001-02-28 22:33:23 +00:00
|
|
|
*
|
|
|
|
* 23-Feb-2001 (Carl Nettelblad <cnettel@hem.passagen.se>)
|
|
|
|
* dir /s now works in deeper trees
|
1999-03-20 20:28:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifdef INCLUDE_CMD_DIR
|
|
|
|
#include <windows.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
1999-04-14 23:48:27 +00:00
|
|
|
#include <stdio.h>
|
1999-03-20 20:28:42 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "cmd.h"
|
|
|
|
|
1999-04-16 17:25:39 +00:00
|
|
|
|
1999-03-20 20:28:42 +00:00
|
|
|
|
|
|
|
/* flag definitions */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
DIR_RECURSE = 0x0001,
|
|
|
|
DIR_PAGE = 0x0002,
|
|
|
|
DIR_WIDE = 0x0004, /* Rob Lake */
|
|
|
|
DIR_BARE = 0x0008, /* Rob Lake */
|
|
|
|
DIR_ALL = 0x0010, /* Rob Lake */
|
|
|
|
DIR_LWR = 0x0020, /* Rob Lake */
|
|
|
|
DIR_SORT = 0x0040, /* /O sort */
|
|
|
|
DIR_NEW = 0x0080, /* /N new style */
|
|
|
|
DIR_FOUR = 0x0100 /* /4 four digit year */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Globally save the # of dirs, files and bytes,
|
|
|
|
* probabaly later pass them to functions. Rob Lake */
|
1999-03-21 21:32:45 +00:00
|
|
|
static ULONG recurse_dir_cnt;
|
|
|
|
static ULONG recurse_file_cnt;
|
|
|
|
static ULARGE_INTEGER recurse_bytes;
|
1999-03-20 20:28:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* help
|
|
|
|
*
|
|
|
|
* displays help screen for dir
|
|
|
|
* Rob Lake
|
|
|
|
*/
|
|
|
|
static VOID Help (VOID)
|
|
|
|
{
|
|
|
|
ConOutPuts (_T("Displays a list of files and subdirectories in a directory.\n"
|
|
|
|
"\n"
|
|
|
|
"DIR [drive:][path][filename] [/A] [/B] [/L] [/N] [/S] [/P] [/W] [/4]\n"
|
|
|
|
"\n"
|
|
|
|
" [drive:][path][filename]\n"
|
|
|
|
" Specifies drive, directory, and/or files to list.\n"
|
|
|
|
"\n"
|
|
|
|
" /A Displays files with HIDDEN SYSTEM attributes\n"
|
|
|
|
" default is ARCHIVE and READ ONLY\n"
|
|
|
|
" /B Uses bare format (no heading information or summary).\n"
|
|
|
|
" /L Uses lowercase.\n"
|
|
|
|
" /N New long list format where filenames are on the far right.\n"
|
|
|
|
" /S Displays files in specified directory and all subdirectories\n"
|
|
|
|
" /P Pauses after each screen full\n"
|
|
|
|
" /W Prints in wide format\n"
|
|
|
|
" /4 Display four digit years.\n"
|
|
|
|
"\n"
|
|
|
|
"Switches may be present in the DIRCMD environment variable. Use\n"
|
|
|
|
"of the - (hyphen) can turn off defined swtiches. Ex. /-W would\n"
|
|
|
|
"turn off printing in wide format.\n"
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1999-03-21 21:32:45 +00:00
|
|
|
* DirReadParam
|
1999-03-20 20:28:42 +00:00
|
|
|
*
|
|
|
|
* read the parameters from the command line
|
|
|
|
*/
|
|
|
|
static BOOL
|
1999-03-21 21:32:45 +00:00
|
|
|
DirReadParam (LPTSTR line, LPTSTR *param, LPDWORD lpFlags)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
INT slash = 0;
|
1999-03-20 20:28:42 +00:00
|
|
|
|
|
|
|
if (!line)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
*param = NULL;
|
|
|
|
|
|
|
|
/* scan the command line, processing switches */
|
|
|
|
while (*line)
|
|
|
|
{
|
|
|
|
/* process switch */
|
|
|
|
if (*line == _T('/') || slash)
|
|
|
|
{
|
|
|
|
if (!slash)
|
|
|
|
line++;
|
|
|
|
slash = 0;
|
|
|
|
if (*line == _T('-'))
|
|
|
|
{
|
|
|
|
line++;
|
|
|
|
if (_totupper (*line) == _T('S'))
|
|
|
|
*lpFlags &= ~DIR_RECURSE;
|
|
|
|
else if (_totupper (*line) == _T('P'))
|
|
|
|
*lpFlags &= ~DIR_PAGE;
|
|
|
|
else if (_totupper (*line) == _T('W'))
|
|
|
|
*lpFlags &= ~DIR_WIDE;
|
|
|
|
else if (_totupper (*line) == _T('B'))
|
|
|
|
*lpFlags &= ~DIR_BARE;
|
|
|
|
else if (_totupper (*line) == _T('A'))
|
|
|
|
*lpFlags &= ~DIR_ALL;
|
|
|
|
else if (_totupper (*line) == _T('L'))
|
|
|
|
*lpFlags &= ~DIR_LWR;
|
|
|
|
else if (_totupper (*line) == _T('N'))
|
|
|
|
*lpFlags &= ~DIR_NEW;
|
|
|
|
else if (_totupper (*line) == _T('O'))
|
|
|
|
*lpFlags &= ~DIR_SORT;
|
|
|
|
else if (_totupper (*line) == _T('4'))
|
|
|
|
*lpFlags &= ~DIR_FOUR;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error_invalid_switch ((TCHAR)_totupper (*line));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
line++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_totupper (*line) == _T('S'))
|
|
|
|
*lpFlags |= DIR_RECURSE;
|
1999-03-30 22:06:36 +00:00
|
|
|
else if (_totupper (*line) == _T('P'))
|
1999-03-20 20:28:42 +00:00
|
|
|
*lpFlags |= DIR_PAGE;
|
|
|
|
else if (_totupper (*line) == _T('W'))
|
|
|
|
*lpFlags |= DIR_WIDE;
|
|
|
|
else if (_totupper (*line) == _T('B'))
|
|
|
|
*lpFlags |= DIR_BARE;
|
|
|
|
else if (_totupper (*line) == _T('A'))
|
|
|
|
*lpFlags |= DIR_ALL;
|
|
|
|
else if (_totupper (*line) == _T('L'))
|
|
|
|
*lpFlags |= DIR_LWR;
|
|
|
|
else if (_totupper (*line) == _T('N'))
|
|
|
|
*lpFlags |= DIR_NEW;
|
|
|
|
else if (_totupper (*line) == _T('O'))
|
|
|
|
*lpFlags |= DIR_SORT;
|
|
|
|
else if (_totupper (*line) == _T('4'))
|
|
|
|
*lpFlags |= DIR_FOUR;
|
|
|
|
else if (*line == _T('?'))
|
|
|
|
{
|
|
|
|
Help();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error_invalid_switch ((TCHAR)_totupper (*line));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
line++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* process parameter */
|
|
|
|
if (!_istspace (*line))
|
|
|
|
{
|
|
|
|
if (*param)
|
|
|
|
{
|
|
|
|
error_too_many_parameters (*param);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*param = line;
|
|
|
|
|
|
|
|
/* skip to end of line or next whitespace or next / */
|
|
|
|
while (*line && !_istspace (*line) && *line != _T('/'))
|
|
|
|
line++;
|
|
|
|
|
|
|
|
/* if end of line, return */
|
|
|
|
if (!*line)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* if parameter, remember to process it later */
|
|
|
|
if (*line == _T('/'))
|
|
|
|
slash = 1;
|
|
|
|
|
|
|
|
*line++ = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
line++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (slash)
|
|
|
|
{
|
|
|
|
error_invalid_switch ((TCHAR)_totupper (*line));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1999-03-21 21:32:45 +00:00
|
|
|
* ExtendFilespec
|
1999-03-20 20:28:42 +00:00
|
|
|
*
|
|
|
|
* extend the filespec, possibly adding wildcards
|
|
|
|
*/
|
1999-03-21 21:32:45 +00:00
|
|
|
static VOID
|
|
|
|
ExtendFilespec (LPTSTR file)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-12-15 00:50:41 +00:00
|
|
|
INT len = 0;
|
1999-05-14 13:32:13 +00:00
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
if (!file)
|
1999-03-20 20:28:42 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* if no file spec, change to "*.*" */
|
1999-03-21 21:32:45 +00:00
|
|
|
if (*file == _T('\0'))
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
_tcscpy (file, _T("*.*"));
|
1999-03-20 20:28:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if starts with . add * in front */
|
1999-03-21 21:32:45 +00:00
|
|
|
if (*file == _T('.'))
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
memmove (&file[1], &file[0], (_tcslen (file) + 1) * sizeof(TCHAR));
|
|
|
|
file[0] = _T('*');
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if no . add .* */
|
1999-03-21 21:32:45 +00:00
|
|
|
if (!_tcschr (file, _T('.')))
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
_tcscat (file, _T(".*"));
|
1999-03-20 20:28:42 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-05-14 13:32:13 +00:00
|
|
|
|
1999-12-15 00:50:41 +00:00
|
|
|
/* if last character is '.' add '*' */
|
|
|
|
len = _tcslen (file);
|
|
|
|
if (file[len - 1] == _T('.'))
|
|
|
|
{
|
|
|
|
_tcscat (file, _T("*"));
|
|
|
|
return;
|
|
|
|
}
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dir_parse_pathspec
|
|
|
|
*
|
|
|
|
* split the pathspec into drive, directory, and filespec
|
|
|
|
*/
|
1999-03-21 21:32:45 +00:00
|
|
|
static INT
|
|
|
|
DirParsePathspec (LPTSTR szPathspec, LPTSTR szPath, LPTSTR szFilespec)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
TCHAR szOrigPath[MAX_PATH];
|
1999-03-20 20:28:42 +00:00
|
|
|
LPTSTR start;
|
|
|
|
LPTSTR tmp;
|
|
|
|
INT i;
|
1999-03-21 21:32:45 +00:00
|
|
|
BOOL bWildcards = FALSE;
|
1999-03-20 20:28:42 +00:00
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
GetCurrentDirectory (MAX_PATH, szOrigPath);
|
1999-03-20 20:28:42 +00:00
|
|
|
|
|
|
|
/* get the drive and change to it */
|
1999-03-21 21:32:45 +00:00
|
|
|
if (szPathspec[1] == _T(':'))
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
TCHAR szRootPath[] = _T("A:");
|
|
|
|
|
|
|
|
szRootPath[0] = szPathspec[0];
|
|
|
|
start = szPathspec + 2;
|
|
|
|
SetCurrentDirectory (szRootPath);
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
start = szPathspec;
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* check for wildcards */
|
1999-03-21 21:32:45 +00:00
|
|
|
for (i = 0; szPathspec[i]; i++)
|
|
|
|
{
|
|
|
|
if (szPathspec[i] == _T('*') || szPathspec[i] == _T('?'))
|
|
|
|
bWildcards = TRUE;
|
|
|
|
}
|
1999-03-20 20:28:42 +00:00
|
|
|
|
|
|
|
/* check if this spec is a directory */
|
1999-03-21 21:32:45 +00:00
|
|
|
if (!bWildcards)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
if (SetCurrentDirectory (szPathspec))
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
_tcscpy (szFilespec, _T("*.*"));
|
1999-03-20 20:28:42 +00:00
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
if (!GetCurrentDirectory (MAX_PATH, szPath))
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
szFilespec[0] = _T('\0');
|
|
|
|
SetCurrentDirectory (szOrigPath);
|
|
|
|
error_out_of_memory();
|
|
|
|
return 1;
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
SetCurrentDirectory (szOrigPath);
|
1999-03-20 20:28:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find the file spec */
|
|
|
|
tmp = _tcsrchr (start, _T('\\'));
|
|
|
|
|
|
|
|
/* if no path is specified */
|
|
|
|
if (!tmp)
|
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
_tcscpy (szFilespec, start);
|
|
|
|
ExtendFilespec (szFilespec);
|
|
|
|
if (!GetCurrentDirectory (MAX_PATH, szPath))
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
szFilespec[0] = _T('\0');
|
|
|
|
SetCurrentDirectory (szOrigPath);
|
|
|
|
error_out_of_memory();
|
|
|
|
return 1;
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
SetCurrentDirectory (szOrigPath);
|
1999-03-20 20:28:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the filename */
|
1999-03-21 21:32:45 +00:00
|
|
|
_tcscpy (szFilespec, tmp+1);
|
|
|
|
ExtendFilespec (szFilespec);
|
1999-03-20 20:28:42 +00:00
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
*tmp = _T('\0');
|
1999-03-20 20:28:42 +00:00
|
|
|
|
|
|
|
/* change to this directory and get its full name */
|
1999-03-21 21:32:45 +00:00
|
|
|
if (!SetCurrentDirectory (start))
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
|
|
|
*tmp = _T('\\');
|
1999-03-21 21:32:45 +00:00
|
|
|
szFilespec[0] = _T('\0');
|
|
|
|
SetCurrentDirectory (szOrigPath);
|
|
|
|
error_path_not_found ();
|
1999-03-20 20:28:42 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
if (!GetCurrentDirectory (MAX_PATH, szPath))
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
*tmp = _T('\\');
|
|
|
|
szFilespec[0] = _T('\0');
|
|
|
|
SetCurrentDirectory (szOrigPath);
|
|
|
|
error_out_of_memory ();
|
|
|
|
return 1;
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*tmp = _T('\\');
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
SetCurrentDirectory (szOrigPath);
|
|
|
|
|
1999-03-20 20:28:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* incline
|
|
|
|
*
|
|
|
|
* increment our line if paginating, display message at end of screen
|
|
|
|
*/
|
1999-12-15 00:50:41 +00:00
|
|
|
static BOOL
|
1999-03-21 21:32:45 +00:00
|
|
|
IncLine (LPINT pLine, DWORD dwFlags)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
|
|
|
if (!(dwFlags & DIR_PAGE))
|
1999-12-15 00:50:41 +00:00
|
|
|
return FALSE;
|
1999-03-20 20:28:42 +00:00
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
(*pLine)++;
|
1999-03-20 20:28:42 +00:00
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
if (*pLine >= (int)maxy - 2)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
*pLine = 0;
|
1999-12-15 00:50:41 +00:00
|
|
|
return (PagePrompt () == PROMPT_BREAK);
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
|
1999-12-15 00:50:41 +00:00
|
|
|
return FALSE;
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PrintDirectoryHeader
|
|
|
|
*
|
|
|
|
* print the header for the dir command
|
|
|
|
*/
|
|
|
|
static BOOL
|
1999-03-21 21:32:45 +00:00
|
|
|
PrintDirectoryHeader (LPTSTR szPath, LPINT pLine, DWORD dwFlags)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
|
|
|
TCHAR szRootName[] = _T("A:\\");
|
|
|
|
TCHAR szVolName[80];
|
|
|
|
DWORD dwSerialNr;
|
|
|
|
|
|
|
|
if (dwFlags & DIR_BARE)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* get the media ID of the drive */
|
1999-03-21 21:32:45 +00:00
|
|
|
szRootName[0] = szPath[0];
|
1999-03-20 20:28:42 +00:00
|
|
|
if (!GetVolumeInformation (szRootName, szVolName, 80, &dwSerialNr,
|
1999-12-15 00:50:41 +00:00
|
|
|
NULL, NULL, NULL, 0))
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
|
|
|
error_invalid_drive();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* print drive info */
|
|
|
|
ConOutPrintf (_T(" Volume in drive %c"), szRootName[0]);
|
|
|
|
|
|
|
|
if (szVolName[0] != _T('\0'))
|
|
|
|
ConOutPrintf (_T(" is %s\n"), szVolName);
|
|
|
|
else
|
|
|
|
ConOutPrintf (_T(" has no label\n"));
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
if (IncLine (pLine, dwFlags))
|
1999-03-20 20:28:42 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* print the volume serial number if the return was successful */
|
|
|
|
ConOutPrintf (_T(" Volume Serial Number is %04X-%04X\n"),
|
1999-12-15 00:50:41 +00:00
|
|
|
HIWORD(dwSerialNr),
|
|
|
|
LOWORD(dwSerialNr));
|
1999-03-21 21:32:45 +00:00
|
|
|
if (IncLine (pLine, dwFlags))
|
1999-03-20 20:28:42 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* convert
|
|
|
|
*
|
|
|
|
* insert commas into a number
|
|
|
|
*/
|
|
|
|
static INT
|
1999-03-21 21:32:45 +00:00
|
|
|
ConvertULong (ULONG num, LPTSTR des, INT len)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
|
|
|
TCHAR temp[32];
|
|
|
|
INT c = 0;
|
|
|
|
INT n = 0;
|
|
|
|
|
|
|
|
if (num == 0)
|
|
|
|
{
|
|
|
|
des[0] = _T('0');
|
|
|
|
des[1] = _T('\0');
|
|
|
|
n = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
temp[31] = 0;
|
|
|
|
while (num > 0)
|
|
|
|
{
|
|
|
|
if (((c + 1) % (nNumberGroups + 1)) == 0)
|
|
|
|
temp[30 - c++] = cThousandSeparator;
|
|
|
|
temp[30 - c++] = (TCHAR)(num % 10) + _T('0');
|
|
|
|
num /= 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (n = 0; n <= c; n++)
|
|
|
|
des[n] = temp[31 - c + n];
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static INT
|
|
|
|
ConvertULargeInteger (ULARGE_INTEGER num, LPTSTR des, INT len)
|
|
|
|
{
|
|
|
|
TCHAR temp[32];
|
|
|
|
INT c = 0;
|
|
|
|
INT n = 0;
|
|
|
|
|
|
|
|
if (num.QuadPart == 0)
|
|
|
|
{
|
|
|
|
des[0] = _T('0');
|
|
|
|
des[1] = _T('\0');
|
|
|
|
n = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
temp[31] = 0;
|
|
|
|
while (num.QuadPart > 0)
|
|
|
|
{
|
|
|
|
if (((c + 1) % (nNumberGroups + 1)) == 0)
|
|
|
|
temp[30 - c++] = cThousandSeparator;
|
|
|
|
temp[30 - c++] = (TCHAR)(num.QuadPart % 10) + _T('0');
|
|
|
|
num.QuadPart /= 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (n = 0; n <= c; n++)
|
|
|
|
des[n] = temp[31 - c + n];
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static VOID
|
|
|
|
PrintFileDateTime (LPSYSTEMTIME dt, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
WORD wYear = (dwFlags & DIR_FOUR) ? dt->wYear : dt->wYear%100;
|
|
|
|
|
|
|
|
switch (nDateFormat)
|
|
|
|
{
|
|
|
|
case 0: /* mmddyy */
|
|
|
|
default:
|
1999-03-21 21:32:45 +00:00
|
|
|
ConOutPrintf (_T("%.2d%c%.2d%c%d"),
|
|
|
|
dt->wMonth, cDateSeparator, dt->wDay, cDateSeparator, wYear);
|
1999-03-20 20:28:42 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* ddmmyy */
|
1999-03-21 21:32:45 +00:00
|
|
|
ConOutPrintf (_T("%.2d%c%.2d%c%d"),
|
1999-03-20 20:28:42 +00:00
|
|
|
dt->wDay, cDateSeparator, dt->wMonth, cDateSeparator, wYear);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* yymmdd */
|
1999-03-21 21:32:45 +00:00
|
|
|
ConOutPrintf (_T("%d%c%.2d%c%.2d"),
|
1999-03-20 20:28:42 +00:00
|
|
|
wYear, cDateSeparator, dt->wMonth, cDateSeparator, dt->wDay);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (nTimeFormat)
|
|
|
|
{
|
|
|
|
case 0: /* 12 hour format */
|
|
|
|
default:
|
1999-03-21 21:32:45 +00:00
|
|
|
ConOutPrintf (_T(" %2d%c%.2u%c"),
|
1999-03-20 20:28:42 +00:00
|
|
|
(dt->wHour == 0 ? 12 : (dt->wHour <= 12 ? dt->wHour : dt->wHour - 12)),
|
|
|
|
cTimeSeparator,
|
|
|
|
dt->wMinute, (dt->wHour <= 11 ? 'a' : 'p'));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* 24 hour format */
|
1999-03-21 21:32:45 +00:00
|
|
|
ConOutPrintf (_T(" %2d%c%.2u"),
|
1999-03-20 20:28:42 +00:00
|
|
|
dt->wHour, cTimeSeparator, dt->wMinute);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* print_summary: prints dir summary
|
|
|
|
* Added by Rob Lake 06/17/98 to compact code
|
|
|
|
* Just copied Tim's Code and patched it a bit
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static INT
|
1999-03-21 21:32:45 +00:00
|
|
|
PrintSummary (LPTSTR szPath, ULONG ulFiles, ULONG ulDirs, ULARGE_INTEGER bytes,
|
|
|
|
LPINT pLine, DWORD dwFlags)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
|
|
|
TCHAR buffer[64];
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
if (dwFlags & DIR_BARE)
|
1999-03-20 20:28:42 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* print number of files and bytes */
|
1999-03-21 21:32:45 +00:00
|
|
|
ConvertULong (ulFiles, buffer, sizeof(buffer));
|
1999-03-20 20:28:42 +00:00
|
|
|
ConOutPrintf (_T(" %6s File%c"),
|
1999-12-15 00:50:41 +00:00
|
|
|
buffer, ulFiles == 1 ? _T(' ') : _T('s'));
|
1999-03-20 20:28:42 +00:00
|
|
|
|
|
|
|
ConvertULargeInteger (bytes, buffer, sizeof(buffer));
|
|
|
|
ConOutPrintf (_T(" %15s byte%c\n"),
|
1999-12-15 00:50:41 +00:00
|
|
|
buffer, bytes.QuadPart == 1 ? _T(' ') : _T('s'));
|
1999-03-20 20:28:42 +00:00
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
if (IncLine (pLine, dwFlags))
|
1999-03-20 20:28:42 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* print number of dirs and bytes free */
|
1999-03-21 21:32:45 +00:00
|
|
|
ConvertULong (ulDirs, buffer, sizeof(buffer));
|
1999-03-20 20:28:42 +00:00
|
|
|
ConOutPrintf (_T(" %6s Dir%c"),
|
1999-12-15 00:50:41 +00:00
|
|
|
buffer, ulDirs == 1 ? _T(' ') : _T('s'));
|
1999-03-20 20:28:42 +00:00
|
|
|
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
if (!(dwFlags & DIR_RECURSE))
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
|
|
|
ULARGE_INTEGER uliFree;
|
|
|
|
TCHAR szRoot[] = _T("A:\\");
|
|
|
|
DWORD dwSecPerCl;
|
|
|
|
DWORD dwBytPerSec;
|
|
|
|
DWORD dwFreeCl;
|
|
|
|
DWORD dwTotCl;
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
szRoot[0] = szPath[0];
|
1999-03-20 20:28:42 +00:00
|
|
|
GetDiskFreeSpace (szRoot, &dwSecPerCl, &dwBytPerSec, &dwFreeCl, &dwTotCl);
|
1999-12-15 00:50:41 +00:00
|
|
|
uliFree.QuadPart = dwSecPerCl * dwBytPerSec * dwFreeCl;
|
1999-03-20 20:28:42 +00:00
|
|
|
ConvertULargeInteger (uliFree, buffer, sizeof(buffer));
|
|
|
|
ConOutPrintf (_T(" %15s bytes free\n"), buffer);
|
|
|
|
}
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
if (IncLine (pLine, dwFlags))
|
1999-03-20 20:28:42 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dir_list
|
|
|
|
*
|
|
|
|
* list the files in the directory
|
|
|
|
*/
|
1999-03-21 21:32:45 +00:00
|
|
|
static INT
|
|
|
|
DirList (LPTSTR szPath, LPTSTR szFilespec, LPINT pLine, DWORD dwFlags)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
TCHAR szFullPath[MAX_PATH];
|
|
|
|
WIN32_FIND_DATA file;
|
|
|
|
ULARGE_INTEGER bytecount;
|
|
|
|
FILETIME ft;
|
|
|
|
SYSTEMTIME dt;
|
|
|
|
HANDLE hFile;
|
|
|
|
TCHAR buffer[32];
|
|
|
|
ULONG filecount = 0;
|
|
|
|
ULONG dircount = 0;
|
|
|
|
INT count;
|
|
|
|
|
|
|
|
bytecount.QuadPart = 0;
|
|
|
|
|
|
|
|
_tcscpy (szFullPath, szPath);
|
|
|
|
if (szFullPath[_tcslen(szFullPath) - 1] != _T('\\'))
|
|
|
|
_tcscat (szFullPath, _T("\\"));
|
|
|
|
_tcscat (szFullPath, szFilespec);
|
|
|
|
|
|
|
|
hFile = FindFirstFile (szFullPath, &file);
|
1999-03-20 20:28:42 +00:00
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
/* Don't want to print anything if scanning recursively
|
|
|
|
* for a file. RL
|
|
|
|
*/
|
1999-03-21 21:32:45 +00:00
|
|
|
if ((dwFlags & DIR_RECURSE) == 0)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
|
|
|
FindClose (hFile);
|
1999-12-15 00:50:41 +00:00
|
|
|
error_file_not_found ();
|
|
|
|
if (IncLine (pLine, dwFlags))
|
|
|
|
return 0;
|
1999-03-20 20:28:42 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
FindClose (hFile);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
/* moved down here because if we are recursively searching and
|
|
|
|
* don't find any files, we don't want just to print
|
|
|
|
* Directory of C:\SOMEDIR
|
|
|
|
* with nothing else
|
|
|
|
* Rob Lake 06/13/98
|
|
|
|
*/
|
|
|
|
if ((dwFlags & DIR_BARE) == 0)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
ConOutPrintf (_T(" Directory of %s\n"), szPath);
|
|
|
|
if (IncLine (pLine, dwFlags))
|
|
|
|
return 1;
|
|
|
|
ConOutPrintf (_T("\n"));
|
|
|
|
if (IncLine (pLine, dwFlags))
|
|
|
|
return 1;
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
/* For counting columns of output */
|
|
|
|
count = 0;
|
1999-03-20 20:28:42 +00:00
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
/* next file, if user doesn't want all files */
|
|
|
|
if (!(dwFlags & DIR_ALL) &&
|
|
|
|
((file.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ||
|
|
|
|
(file.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (dwFlags & DIR_LWR)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
_tcslwr (file.cAlternateFileName);
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
1999-03-21 21:32:45 +00:00
|
|
|
|
|
|
|
if (dwFlags & DIR_WIDE && (dwFlags & DIR_BARE) == 0)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
|
|
|
ULARGE_INTEGER uliSize;
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
{
|
|
|
|
if (file.cAlternateFileName[0] == _T('\0'))
|
1999-04-14 23:48:27 +00:00
|
|
|
_stprintf (buffer, _T("[%s]"), file.cFileName);
|
1999-03-21 21:32:45 +00:00
|
|
|
else
|
1999-04-14 23:48:27 +00:00
|
|
|
_stprintf (buffer, _T("[%s]"), file.cAlternateFileName);
|
1999-03-21 21:32:45 +00:00
|
|
|
dircount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (file.cAlternateFileName[0] == _T('\0'))
|
1999-04-14 23:48:27 +00:00
|
|
|
_stprintf (buffer, _T("%s"), file.cFileName);
|
1999-03-21 21:32:45 +00:00
|
|
|
else
|
1999-04-14 23:48:27 +00:00
|
|
|
_stprintf (buffer, _T("%s"), file.cAlternateFileName);
|
1999-03-21 21:32:45 +00:00
|
|
|
filecount++;
|
|
|
|
}
|
1999-03-20 20:28:42 +00:00
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
ConOutPrintf (_T("%-15s"), buffer);
|
|
|
|
count++;
|
|
|
|
if (count == 5)
|
|
|
|
{
|
|
|
|
/* output 5 columns */
|
|
|
|
ConOutPrintf (_T("\n"));
|
|
|
|
if (IncLine (pLine, dwFlags))
|
|
|
|
return 1;
|
|
|
|
count = 0;
|
|
|
|
}
|
1999-03-20 20:28:42 +00:00
|
|
|
|
1999-05-11 12:40:11 +00:00
|
|
|
uliSize.u.LowPart = file.nFileSizeLow;
|
|
|
|
uliSize.u.HighPart = file.nFileSizeHigh;
|
1999-03-20 20:28:42 +00:00
|
|
|
bytecount.QuadPart += uliSize.QuadPart;
|
|
|
|
}
|
1999-03-21 21:32:45 +00:00
|
|
|
else if (dwFlags & DIR_BARE)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
ULARGE_INTEGER uliSize;
|
1999-03-20 20:28:42 +00:00
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
if (_tcscmp (file.cFileName, _T(".")) == 0 ||
|
|
|
|
_tcscmp (file.cFileName, _T("..")) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (dwFlags & DIR_RECURSE)
|
|
|
|
{
|
|
|
|
TCHAR dir[MAX_PATH];
|
|
|
|
|
|
|
|
_tcscpy (dir, szPath);
|
|
|
|
_tcscat (dir, _T("\\"));
|
|
|
|
if (dwFlags & DIR_LWR)
|
|
|
|
_tcslwr (dir);
|
|
|
|
ConOutPrintf (dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
ConOutPrintf (_T("%-13s\n"), file.cFileName);
|
|
|
|
if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
dircount++;
|
|
|
|
else
|
|
|
|
filecount++;
|
|
|
|
if (IncLine (pLine, dwFlags))
|
|
|
|
return 1;
|
|
|
|
|
1999-05-11 12:40:11 +00:00
|
|
|
uliSize.u.LowPart = file.nFileSizeLow;
|
|
|
|
uliSize.u.HighPart = file.nFileSizeHigh;
|
1999-03-21 21:32:45 +00:00
|
|
|
bytecount.QuadPart += uliSize.QuadPart;
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
if (dwFlags & DIR_NEW)
|
|
|
|
{
|
|
|
|
/* print file date and time */
|
|
|
|
if (FileTimeToLocalFileTime (&file.ftLastWriteTime, &ft))
|
|
|
|
{
|
|
|
|
FileTimeToSystemTime (&ft, &dt);
|
|
|
|
PrintFileDateTime (&dt, dwFlags);
|
|
|
|
}
|
1999-03-20 20:28:42 +00:00
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
/* print file size */
|
|
|
|
if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
{
|
|
|
|
ConOutPrintf (_T(" <DIR> "));
|
|
|
|
dircount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ULARGE_INTEGER uliSize;
|
1999-03-20 20:28:42 +00:00
|
|
|
|
1999-05-11 12:40:11 +00:00
|
|
|
uliSize.u.LowPart = file.nFileSizeLow;
|
|
|
|
uliSize.u.HighPart = file.nFileSizeHigh;
|
1999-03-20 20:28:42 +00:00
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
ConvertULargeInteger (uliSize, buffer, sizeof(buffer));
|
|
|
|
ConOutPrintf (_T(" %20s"), buffer);
|
1999-03-20 20:28:42 +00:00
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
bytecount.QuadPart += uliSize.QuadPart;
|
1999-05-11 12:40:11 +00:00
|
|
|
filecount++;
|
1999-03-21 21:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* print long filename */
|
|
|
|
ConOutPrintf (_T(" %s\n"), file.cFileName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (file.cFileName[0] == _T('.'))
|
|
|
|
ConOutPrintf (_T("%-13s "), file.cFileName);
|
|
|
|
else if (file.cAlternateFileName[0] == _T('\0'))
|
|
|
|
{
|
|
|
|
TCHAR szShortName[13];
|
|
|
|
LPTSTR ext;
|
|
|
|
|
|
|
|
_tcsncpy (szShortName, file.cFileName, 13);
|
|
|
|
ext = _tcschr (szShortName, _T('.'));
|
|
|
|
if (!ext)
|
|
|
|
ext = _T("");
|
|
|
|
else
|
|
|
|
*ext++ = _T('\0');
|
|
|
|
ConOutPrintf (_T("%-8s %-3s "), szShortName, ext);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPTSTR ext;
|
|
|
|
|
|
|
|
ext = _tcschr (file.cAlternateFileName, _T('.'));
|
|
|
|
if (!ext)
|
|
|
|
ext = _T("");
|
|
|
|
else
|
|
|
|
*ext++ = _T('\0');
|
|
|
|
ConOutPrintf (_T("%-8s %-3s "), file.cAlternateFileName, ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* print file size */
|
|
|
|
if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
{
|
|
|
|
ConOutPrintf ("%-14s", "<DIR>");
|
|
|
|
dircount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ULARGE_INTEGER uliSize;
|
1999-03-20 20:28:42 +00:00
|
|
|
|
1999-05-11 12:40:11 +00:00
|
|
|
uliSize.u.LowPart = file.nFileSizeLow;
|
|
|
|
uliSize.u.HighPart = file.nFileSizeHigh;
|
|
|
|
ConvertULargeInteger (uliSize, buffer, sizeof(buffer));
|
1999-03-21 21:32:45 +00:00
|
|
|
ConOutPrintf (_T(" %10s "), buffer);
|
|
|
|
bytecount.QuadPart += uliSize.QuadPart;
|
|
|
|
filecount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* print file date and time */
|
|
|
|
if (FileTimeToLocalFileTime (&file.ftLastWriteTime, &ft))
|
|
|
|
{
|
|
|
|
FileTimeToSystemTime (&ft, &dt);
|
|
|
|
PrintFileDateTime (&dt, dwFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* print long filename */
|
|
|
|
ConOutPrintf (" %s\n", file.cFileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IncLine (pLine, dwFlags))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (FindNextFile (hFile, &file));
|
|
|
|
FindClose (hFile);
|
1999-03-20 20:28:42 +00:00
|
|
|
|
|
|
|
/* Rob Lake, need to make clean output */
|
|
|
|
/* JPP 07/08/1998 added check for count != 0 */
|
1999-03-21 21:32:45 +00:00
|
|
|
if ((dwFlags & DIR_WIDE) && (count != 0))
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
ConOutPrintf (_T("\n"));
|
|
|
|
if (IncLine (pLine, dwFlags))
|
1999-03-20 20:28:42 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filecount || dircount)
|
|
|
|
{
|
|
|
|
recurse_dir_cnt += dircount;
|
|
|
|
recurse_file_cnt += filecount;
|
|
|
|
recurse_bytes.QuadPart += bytecount.QuadPart;
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
/* print_summary */
|
|
|
|
if (PrintSummary (szPath, filecount, dircount, bytecount, pLine, dwFlags))
|
1999-03-20 20:28:42 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error_file_not_found ();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _Read_Dir: Actual function that does recursive listing
|
|
|
|
*/
|
1999-03-21 21:32:45 +00:00
|
|
|
static INT
|
|
|
|
DirRead (LPTSTR szPath, LPTSTR szFilespec, LPINT pLine, DWORD dwFlags)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
TCHAR szFullPath[MAX_PATH];
|
|
|
|
WIN32_FIND_DATA file;
|
|
|
|
HANDLE hFile;
|
|
|
|
|
|
|
|
_tcscpy (szFullPath, szPath);
|
|
|
|
if (szFullPath[_tcslen (szFullPath) - 1] != _T('\\'))
|
|
|
|
_tcscat (szFullPath, _T("\\"));
|
|
|
|
_tcscat (szFullPath, szFilespec);
|
|
|
|
|
|
|
|
hFile = FindFirstFile (szFullPath, &file);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* don't list "." and ".." */
|
|
|
|
if (_tcscmp (file.cFileName, _T(".")) == 0 ||
|
|
|
|
_tcscmp (file.cFileName, _T("..")) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
{
|
2001-02-28 22:33:23 +00:00
|
|
|
_tcscpy (szFullPath, szPath);
|
|
|
|
if (szFullPath[_tcslen (szFullPath) - 1] != _T('\\'))
|
|
|
|
_tcscat (szFullPath, _T("\\"));
|
|
|
|
_tcscat (szFullPath, file.cFileName);
|
|
|
|
|
|
|
|
if (DirList (szFullPath, szFilespec, pLine, dwFlags))
|
1999-03-21 21:32:45 +00:00
|
|
|
{
|
|
|
|
FindClose (hFile);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((dwFlags & DIR_BARE) == 0)
|
|
|
|
{
|
|
|
|
ConOutPrintf ("\n");
|
|
|
|
if (IncLine (pLine, dwFlags) != 0)
|
|
|
|
return 1;
|
2001-02-28 22:33:23 +00:00
|
|
|
ConOutPrintf ("\n");
|
|
|
|
if (IncLine (pLine, dwFlags) != 0)
|
|
|
|
return 1;
|
1999-03-21 21:32:45 +00:00
|
|
|
}
|
|
|
|
|
2001-02-28 22:33:23 +00:00
|
|
|
if (DirRead (szFullPath, szFilespec, pLine, dwFlags) == 1)
|
1999-03-21 21:32:45 +00:00
|
|
|
{
|
|
|
|
FindClose (hFile);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (FindNextFile (hFile, &file));
|
|
|
|
|
|
|
|
if (!FindClose (hFile))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* do_recurse: Sets up for recursive directory listing
|
|
|
|
*/
|
1999-03-21 21:32:45 +00:00
|
|
|
static INT
|
|
|
|
DirRecurse (LPTSTR szPath, LPTSTR szSpec, LPINT pLine, DWORD dwFlags)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
if (!PrintDirectoryHeader (szPath, pLine, dwFlags))
|
|
|
|
return 1;
|
1999-03-20 20:28:42 +00:00
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
if (DirList (szPath, szSpec, pLine, dwFlags))
|
|
|
|
return 1;
|
1999-03-20 20:28:42 +00:00
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
if ((dwFlags & DIR_BARE) == 0)
|
|
|
|
{
|
|
|
|
ConOutPrintf (_T("\n"));
|
|
|
|
if (IncLine (pLine, dwFlags))
|
|
|
|
return 1;
|
|
|
|
}
|
1999-03-20 20:28:42 +00:00
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
if (DirRead (szPath, szSpec, pLine, dwFlags))
|
1999-03-20 20:28:42 +00:00
|
|
|
return 1;
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
if ((dwFlags & DIR_BARE) == 0)
|
|
|
|
ConOutPrintf (_T("Total files listed:\n"));
|
|
|
|
|
|
|
|
dwFlags &= ~DIR_RECURSE;
|
|
|
|
|
|
|
|
if (PrintSummary (szPath, recurse_file_cnt,
|
1999-05-11 12:40:11 +00:00
|
|
|
recurse_dir_cnt, recurse_bytes, pLine, dwFlags))
|
1999-03-20 20:28:42 +00:00
|
|
|
return 1;
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
if ((dwFlags & DIR_BARE) == 0)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
ConOutPrintf (_T("\n"));
|
|
|
|
if (IncLine (pLine, dwFlags))
|
1999-03-20 20:28:42 +00:00
|
|
|
return 1;
|
|
|
|
}
|
1999-03-21 21:32:45 +00:00
|
|
|
|
1999-03-20 20:28:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dir
|
|
|
|
*
|
|
|
|
* internal dir command
|
|
|
|
*/
|
1999-12-15 00:50:41 +00:00
|
|
|
INT CommandDir (LPTSTR first, LPTSTR rest)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
1999-03-21 21:32:45 +00:00
|
|
|
DWORD dwFlags = DIR_NEW | DIR_FOUR;
|
|
|
|
TCHAR dircmd[256];
|
|
|
|
TCHAR szPath[MAX_PATH];
|
|
|
|
TCHAR szFilespec[MAX_PATH];
|
|
|
|
LPTSTR param;
|
|
|
|
INT nLine = 0;
|
1999-03-20 20:28:42 +00:00
|
|
|
|
|
|
|
|
1999-04-27 14:15:56 +00:00
|
|
|
recurse_dir_cnt = 0L;
|
|
|
|
recurse_file_cnt = 0L;
|
|
|
|
recurse_bytes.QuadPart = 0;
|
|
|
|
|
1999-03-20 20:28:42 +00:00
|
|
|
/* read the parameters from the DIRCMD environment variable */
|
|
|
|
if (GetEnvironmentVariable (_T("DIRCMD"), dircmd, 256))
|
|
|
|
{
|
|
|
|
if (!DirReadParam (dircmd, ¶m, &dwFlags))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the parameters */
|
|
|
|
if (!DirReadParam (rest, ¶m, &dwFlags))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* default to current directory */
|
|
|
|
if (!param)
|
|
|
|
param = ".";
|
|
|
|
|
|
|
|
/* parse the directory info */
|
1999-03-21 21:32:45 +00:00
|
|
|
if (DirParsePathspec (param, szPath, szFilespec))
|
1999-03-20 20:28:42 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (dwFlags & DIR_RECURSE)
|
|
|
|
{
|
1999-12-15 00:50:41 +00:00
|
|
|
if (IncLine (&nLine, dwFlags))
|
|
|
|
return 0;
|
1999-03-21 21:32:45 +00:00
|
|
|
if (DirRecurse (szPath, szFilespec, &nLine, dwFlags))
|
1999-03-20 20:28:42 +00:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* print the header */
|
1999-03-21 21:32:45 +00:00
|
|
|
if (!PrintDirectoryHeader (szPath, &nLine, dwFlags))
|
1999-03-20 20:28:42 +00:00
|
|
|
return 1;
|
|
|
|
|
1999-03-21 21:32:45 +00:00
|
|
|
if (DirList (szPath, szFilespec, &nLine, dwFlags))
|
1999-03-20 20:28:42 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
1999-12-15 00:50:41 +00:00
|
|
|
|
|
|
|
/* EOF */
|