Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Does anyone have a VBA routine that would would print the name of each
subdirectory and the contents of each of these directories into a text file? For example you would point it to a specified directory and the routine would locate each subdirectory and print the subdirectory name and its contents to a text file then locate the next subdirectory and print its contents etc, etc. The final output would list each subdirectory and all its contents. Thanks -- Ray |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try this:
Sub ListDir() Shell "CMD /C DIR C:\AJAY /S /B C:\MYFILES.TXT" End Sub The file C:\MYFILES.TXT will contain what you are after. "Ray" wrote: Does anyone have a VBA routine that would would print the name of each subdirectory and the contents of each of these directories into a text file? For example you would point it to a specified directory and the routine would locate each subdirectory and print the subdirectory name and its contents to a text file then locate the next subdirectory and print its contents etc, etc. The final output would list each subdirectory and all its contents. Thanks -- Ray |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Directory to a File
Thank you AA2e72E this is simple elegant and powerful. Sub ListDir() Shell "CMD /C DIR C:\AJAY /S /B C:\MYFILES.TXT" End Sub Note that several commands are being nested. CMD calls up an instance of a Dos based window. DIR run the Directory command on C:\Ajay directory. The Directory command is implementing two switches /s to include files in all subdirectories /b to use the file bare. File bare omits directory headings, size, and date stamps. is a redirect which redirects theo output of the subsequent nested commands and switches to a file C:\myfiles.txt. The dos window closed upon execution, so the /C switch probably is a slash command for the CMD nesting. Subsequent to this you can run a transfer text routine to bring in the current directory data. This example worked with my modification the first time. This is a rare gift. Shell "CMD /C DIR p:\*.txt /S /B C:\MYFILES.TXT" In the past I had written a dos batch file to accomplish this. In addition the netuse command to map network unc paths to a drive letter before this command works. Bottom line: I will use the different dos based command switches to accomplish many different file and directory queries. Im upgrading to Windows XP from Windows 98. The NT directory Windows XP, NT, 2000, DIR and the Windows 95, 98, ME, 3.1 Dos DIR outputs are different. However, the /B swith for the bare file name may be consistent regardless of Dos command. Below is a paste of Unicode text of Microsoft Help files. They are copyrighted, however since this is a Microsoft site It should not matter. This is a Roseta stone for this type of work. Below you will find help for the command and switches as follows: CMD, DIR, Redirects and Pipes | Help Recitals CmdStarts a new instance of the command interpreter, Cmd.exe. Used without parameters, cmd displays Windows XP version and copyright information. Syntax cmd [[{/c|/k}] [/s] [/q] [/d] [{/a|/u}] [/t:fg] [/e:{on|off}] [/f:{on|off}] [/v:{on|off}] string] Parameters /c Carries out the command specified by string and then stops. /k Carries out the command specified by string and continues. /s Modifies the treatment of string after /c or /k. /q Turns the echo off. /d Disables execution of AutoRun commands. /a Creates American National Standards Institute (ANSI) output. /u Creates Unicode output. /t:fg Sets the foreground f and background g colors. The following tables lists valid hexadecimal digits that you can use as the values for f and g. Value Color 0 Black 1 Blue 2 Green 3 Aqua 4 Red 5 Purple 6 Yellow 7 White 8 Gray 9 Light blue A Light green B Light aqua C Light red D Light purple E Light yellow F Bright white /e:on Enables command extensions. /e:off Disables commands extensions. /f:on Enables file and directory name completion. /f:off Disables file and directory name completion. /v:on Enables delayed environment variable expansion. /v:off Disables delayed environment variable expansion. string Specifies the command you want to carry out. /? Displays help at the command prompt. Remarks Using multiple commands You can use multiple commands separated by the command separator && for string, but you must enclose them in quotation marks (for example, "command&&command&&command"). Processing quotation marks If you specify /c or /k, cmd processes the remainder of string and quotation marks are preserved only if all of the following conditions are met: You do not use /s. You use exactly one set of quotation marks. You do not use any special characters within the quotation marks (for example: &<( ) @ ^ |). You use one or more white-space characters within the quotation marks. The string within quotation marks is the name of an executable file. If the previous conditions are not met, string is processed by examining the first character to verify whether or not it is an opening quotation mark. If the first character is an opening quotation mark, it is stripped along with the closing quotation mark. Any text following the closing quotation marks is preserved. Executing registry subkeys If you do not specify /d in string, Cmd.exe looks for the following registry subkeys: HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun\REG_SZ HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun REG_EXPAND_SZ If either one or both registry subkeys are present, they are executed before all other variables. Caution Incorrectly editing the registry may severely damage your system. Before making changes to the registry, you should back up any valued data on the computer. Enabling and disabling command extensions Command extensions are enabled by default in Windows XP. You can disable them for a particular process by using /e:off. You can enable or disable extensions for all cmd command-line options on a computer or user session by setting the following REG_DWORD values: HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\EnableExtensions\REG_DWORD HKEY_CURRENT_USER\Software\Microsoft\Command Processor\EnableExtensions\REG_DWORD Set the REG_DWORD value to either 0ร1 (that is, enabled) or 0ร0 (that is, disabled) in the registry by using Regedit.exe. User-specified settings take precedence over computer settings, and command-line options take precedence over registry settings. Caution Incorrectly editing the registry may severely damage your system. Before making changes to the registry, you should back up any valued data on the computer. When you enable command extensions, the following commands are affected: assoc call chdir (cd) color del (erase) endlocal for ftype goto if mkdir (md) popd prompt pushd set setlocal shift start (also includes changes to external command processes) For more information about these commands, see Related Topics. Enabling delayed environment variable expansion If you enable delayed environment variable expansion, you can use the exclamation character to substitute the value of an environment variable at run time. Enabling file and directory name completion File and directory name completion is not enabled by default. You can enable or disable file name completion for a particular process of the cmd command with /f:{on|off}. You can enable or disable file and directory name completion for all processes of the cmd command on a computer or user logon session by setting the following REG_DWORD values: HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\CompletionChar\REG_DWORD HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\PathCompletionChar\REG_DWORD HKEY_CURRENT_USER\Software\Microsoft\Command Processor\CompletionChar\REG_DWORD HKEY_CURRENT_USER\Software\Microsoft\Command Processor\PathCompletionChar\REG_DWORD To set the REG_DWORD value, run Regedit.exe and use the hexadecimal value of a control character for a particular function (for example, 0ร9 is TAB and 0ร08 is BACKSPACE). User-specified settings take precedence over computer settings, and command-line options take precedence over registry settings. Caution Incorrectly editing the registry may severely damage your system. Before making changes to the registry, you should back up any valued data on the computer. If you enable file and directory name completion by using /f:on, use CTRL+D for directory name completion and CTRL+F for file name completion. To disable a particular completion character in the registry, use the value for white space [0ร20] because it is not a valid control character. When you press CTRL+D or CTRL+F, cmd processes file and directory name completion. These key combination functions append a wildcard character to string (that is, if one is not present), build a list of paths that match, and then display the first matching path. If none of the paths match, the file and directory name completion function beeps and does not change the display. To move through the list of matching paths, press CTRL+D or CTRL+F repeatedly. To move through the list backwards, press the SHIFT key and CTRL+D or CTRL+F simultaneously. To discard the saved list of matching paths and generate a new list, edit string and press CTRL+D or CTRL+F. If you switch between CTRL+D and CTRL+F, the saved list of matching paths is discarded and a new list is generated. The only difference between the key combinations CTRL+D and CTRL+F is that CTRL+D only matches directory names and CTRL+F matches both file and directory names. If you use file and directory name completion on any of the built-in directory commands (that is, CD, MD, or RD), directory completion is assumed. File and directory name completion correctly processes file names that contain white space or special characters if you place quotation marks around the matching path. The following special characters require quotation marks: & < [ ] { } ^ = ; ! ' + , ` ~ [white space] If the information that you supply contains spaces, use quotation marks around the text (for example, "Computer Name"). If you process file and directory name completion from within string, any part of the [Path] to the right of the cursor is discarded (that is, at the point in string where the completion was processed). Formatting legend Format Meaning Italic Information that the user must supply Bold Elements that the user must type exactly as shown Ellipsis (...) Parameter that can be repeated several times in a command line Between brackets ([]) Optional items Between braces ({}); choices separated by pipe (|). Example: {even|odd} Set of choices from which the user must choose only one Courier font Code or program output DirDisplays a list of a directory's files and subdirectories. Used without parameters, dir displays the disk's volume label and serial number, followed by a list of directories and files on the disk, including their names and the date and time each was last modified. For files, dir displays the name extension and the size in bytes. Dir also displays the total number of files and directories listed, their cumulative size, and the free space (in bytes) remaining on the disk. Syntax dir [Drive:][Path][FileName] [...] [/p] [/q] [/w] [/d] [/a[[:]attributes]][/o[[:]SortOrder]] [/t[[:]TimeField]] [/s] [/b] [/l] [/n] [/x] [/c] [/4] Parameters [Drive:][Path] Specifies the drive and directory for which you want to see a listing. [FileName] Specifies a particular file or group of files for which you want to see a listing. /p Displays one screen of the listing at a time. To see the next screen, press any key on the keyboard. /q Displays file ownership information. /w Displays the listing in wide format, with as many as five file names or directory names on each line. /d Same as /w but files are sorted by column. /a [[:] attributes] Displays only the names of those directories and files with the attributes you specify. If you omit /a, dir displays the names of all files except hidden and system files. If you use /a without specifying attributes, dir displays the names of all files, including hidden and system files. The following list describes each of the values you can use for attributes. The colon (:) is optional. Use any combination of these values, and do not separate the values with spaces. Value Description h Hidden files s System files d Directories a Files ready for archiving r Read-only files -h Files that are not hidden -s Files other than system files -d Files only (not directories) -a Files that have not changed since the last backup -r Files that are not read-only /o [[:]SortOrder] Controls the order in which dir sorts and displays directory names and file names. If you omit /o, dir displays the names in the order in which they occur in the directory. If you use /o without specifying SortOrder, dir displays the names of the directories, sorted in alphabetic order, and then displays the names of files, sorted in alphabetic order. The colon (:) is optional. The following list describes each of the values you can use for SortOrder. Use any combination of the values, and do not separate these values with white spaces. Value Description n In alphabetic order by name e In alphabetic order by extension d By date and time, earliest first s By size, smallest first g With directories grouped before files -n In reverse alphabetic order by name (Z through A) -e In reverse alphabetic order by extension (.ZZZ through .AAA) -d By date and time, latest first -s By size, largest first -g With directories grouped after files /t [[:]TimeField] Specifies which time field to display or use for sorting. The following list describes each of the values you can use for TimeField. Value Description c Creation a Last access w Last written /s Lists every occurrence, in the specified directory and all subdirectories, of the specified file name. /b Lists each directory name or file name, one per line, including the file name extension. /b does not display heading information or a summary. /b overrides /w. /l Displays unsorted directory names and file names in lowercase. /l does not convert extended characters to lowercase. /n Displays a long list format with file names on the far right of the screen. /x Displays the short names generated for files on NTFS and FAT volumes. The display is the same as the display for /n, but short names are displayed after the long name. /c Displays the thousand separator in file sizes. /4 Displays four-digit year format. /? Displays help at the command prompt. Remarks Using multiple filenames You can use multiple filenames. Separate file names with spaces, commas, or semicolons. You can use wildcard characters (that is, ? and *) in FileName to display a group of files. Using wildcards You can use wildcards (that is, ? and *) to display a list of a subset of files and subdirectories. Specifying file display attributes If you use /a with more than one value in attributes, dir displays the names of only those files with all the specified attributes. For example, if you use /a with r and -h for attributes by using either /a:r-h or /ar-h, dir displays only the names of read-only files that are not hidden. Specifying file name sorting If you specify more than one SortOrder value, dir sorts the file names by the first criterion first, then by the second criterion, and so on. For example, if you use /o with the e and -s values for SortOrder by using either /o:e-s or /oe-s, dir sorts the names of directories and files by extension, with the largest first, and then displays the final result. The alphabetic sorting by extension causes file names with no extensions to appear first, then directory names, and then file names with extensions. Using redirection symbols and pipes When you use a redirection symbol () to send dir output to a file or a pipe (|) to send dir output to another command, use /a:-d and /b to list the file names only. You can use FileName with /b and /s to specify that dir is to search the current directory and its subdirectories for all file names that match FileName. Dir lists only the drive letter, directory name, file name, and file name extension, one path per line, for each file name it finds. Before you use a pipe for redirection, you should set the TEMP environment variable in your Autoexec.nt file. Presetting dir parameters You can preset dir parameters by including set with the DIRCMD environment variable in your Autoexec.nt file. You can use any valid combination of dir parameters with set dircmd, including the location and name of a file. For example, to use the DIRCMD environment variable to set the wide display format (that is, /w) as the default format, type the following command in your Autoexec.nt file: set dircmd=/w For a single use of the dir command, you can override a parameter by using the DIRCMD environment variable. To do so, type the parameter that you want to override at the dir command prompt, preceding the parameter with a minus sign. For example: dir /-w To change the DIRCMD default settings, type: set=NewParameter The new default settings are effective for all subsequent dir commands until you use set dircmd again or until you restart your computer. To clear all default settings, type: set dircmd= To view the current settings of the DIRCMD environment variable, type: set Set displays a list of environment variables and their settings. For more information about setting environment variables, see Related Topics. The dir command, with different parameters, is available from the Recovery Console. Examples To display all directories, one after the other, in alphabetical order, in wide format and pausing after each screen, make sure that the root directory is the current directory, and then type: dir /s/w/o/p Dir lists the name of the root directory, the names of the subdirectories of the root directory, and the names of the files in the root directory, including extensions. Then, dir lists the subdirectory names and file names in each subdirectory in the tree. To alter the preceding example so that dir displays the file names and extensions, but omits the directory names, type: dir /s/w/o/p/a:-d To print a directory listing, type: ir prn When you specify prn, the directory list is sent to the printer attached to the LPT1 port. If your printer is attached to a different port, you must replace prn with the name of the correct port. You can also redirect output of the dir command to a file by replacing prn with a file name. You can also type a path. For example, to direct dir output to the file Dir.doc in the Records directory, type: dir \records\dir.doc If Dir.doc does not exist, dir creates it, unless the Records directory does not exist. In that case, the following message appears: File creation error To display a list of all the file names with the .txt extension in all directories on drive C, type: dir c:\*.txt /w/o/s/p Dir displays, in wide format, an alphabetized list of the matching file names in each directory and pauses each time the screen fills up, until you press a key to continue. Formatting legend Format Meaning Italic Information that the user must supply Bold Elements that the user must type exactly as shown Ellipsis (...) Parameter that can be repeated several times in a command line Between brackets ([]) Optional items Between braces ({}); choices separated by pipe (|). Example: {even|odd} Set of choices from which the user must choose only one Courier font Code or program output Using command redirection operatorsYou can use redirection operators to redirect command input and output streams from the default locations to different locations. The input or output stream location is referred to as a handle. The following table lists operators that you can use to redirect command input and output streams. Redirection operator Description Writes the command output to a file or a device, such as a printer, instead of the Command Prompt window. < Reads the command input from a file, instead of reading input from the keyboard. Appends the command output to the end of a file without deleting the information that is already in the file. & Writes the output from one handle to the input of another handle. <& Reads the input from one handle and writes it to the output of another handle. | Reads the output from one command and writes it to the input of another command. Also known as a pipe. By default, you send the command input (that is, the STDIN handle) from your keyboard to Cmd.exe, and then Cmd.exe sends the command output (that is, the STDOUT handle) to the Command Prompt window. The following table lists the available handles. Handle Numeric equivalent of handle Description STDIN 0 Keyboard input STDOUT 1 Output to the Command Prompt window STDERR 2 Error output to the Command Prompt window UNDEFINED 3-9 These handles are defined individually by the application and are specific to each tool. The numbers zero through nine (that is, 0-9) represent the first 10 handles. You can use Cmd.exe to run a program and redirect any of the first 10 handles for the program. To specify which handle you want to use, type the number of the handle before the redirection operator. If you do not define a handle, the default < redirection input operator is zero (0) and the default redirection output operator is one (1). After you type the < or operator, you must specify where you want to read or write the data. You can specify a file name or another existing handle. To specify redirection to existing handles, use the ampersand (&) character followed by the handle number that you want to redirect (that is, &handle#). For example, the following command redirects handle 2 (that is, STDERR) into handle 1 (that is, STDOUT): 1<&2 Duplicating handles The & redirection operator duplicates output or input from one specified handle to another specified handle. For example, to send dir output to File.txt and send the error output to File.txt, type: dirc:\file.txt 2&1 When you duplicate a handle, you duplicate all characteristics of the original occurrence of the handle. For example, if a handle has write-only access, all duplicates of that handle have write-only access. You cannot duplicate a handle with read-only access into a handle with write-only access. Redirecting command input (<) To redirect command input from the keyboard to a file or device, use the < operator. For example, to get the command input for the sort command from File.txt: sort<file.txt The contents of File.txt appear in the Command Prompt window as an alphabetized list. The < operator opens the specified file name with read-only access. As a result, you cannot write to the file when you use this operator. For example, if you start a program with <&2, all attempts to read handle 0 fail because handle 2 is initially opened with write-only access. Note Zero is the default handle for the < redirection input operator. Redirecting command output () Almost all commands send output to your Command Prompt window. Even commands that send output to a drive or printer display messages and prompts in the Command Prompt window. To redirect command output from the Command Prompt window to a file or device, use the operator. You can use this operator with most commands. For example, to redirect dir output to Dirlist.txt: dirdirlist.txt If Dirlist.txt does not exist, Cmd.exe creates it. If Dirlist.txt exists, Cmd.exe replaces the information in the file with the output from the dir command. To run the netsh routing dump command and then send the command output to Route.cfg, type: netsh routing dumpc:\route.cfg The operator opens the specified file with write-only access. As a result, you cannot read the file when you use this operator. For example, if you start a program with redirection &0, all attempts to write handle 1 fail because handle 0 is initially opened with read-only access. Note One is the default handle for the redirection output operator. Using the <& operator to redirect input and duplicate To use the redirection input operator <&, the file you specify must already exist. If the input file exists, Cmd.exe opens it as read-only and sends the characters contained in the file as input to the command as if they were input from the keyboard. If you specify a handle, Cmd.exe duplicates the handle you specify onto the existing handle in the system. For example, to open File.txt as input read to handle 0 (that is, STDIN), type: <file.txt To open File.txt, sort the contents and then send the output to the Command Prompt window (that is, STDOUT), type: sort<file.txt To find File.txt, and then redirect handle 1 (that is, STDOUT) and handle 2 (that is, STDERR) to the Search.txt, type: findfile file.txtsearch.txt 2<&1 To duplicate a user-defined handle 3 as input read to handle 0 (that is, STDIN), type: <&3 Using the & operator to redirect output and duplicate If you redirect output to a file and you specify an existing file name, Cmd.exe opens the file as write-only and overwrites the file's contents. If you specify a handle, Cmd.exe duplicates the file onto the existing handle. To duplicate a user-defined handle 3 into handle 1, type: &3 To redirect all of the output, including handle 2 (that is, STDERR), from the ipconfig command to handle 1 (that is, STDOUT), and then redirect the ouput to Output.log, type: ipconfig.exeoutput.log 2&1 Using the redirection operator to append output To add the output from a command to the end of a file without losing any of the information already in the file, use two consecutive greater than signs (that is, ). For example, the following command appends the directory list produced by the dir command to the Dirlist.txt file: dirdirlist.txt To append the output of the netstat command to the end of Tcpinfo.txt, type: netstattcpinfo.txt Using the pipe operator (|) The pipe operator (|) takes the output (by default, STDOUT) of one command and directs it into the input (by default, STDIN) of another command. For example, the following command sorts a directory: dir | sort In this example, both commands start simultaneously, but then the sort command pauses until it receives the dir command's output. The sort command uses the dir command's output as its input, and then sends its output to handle 1 (that is, STDOUT). Combining commands with redirection operators You can create custom commands by combining filter commands with other commands and file names. For example, you can use the following command to store the names of files that contain the string "LOG": dir /b | find "LOG" loglist.txt The dir command's output is sent through the find filter command. File names that contain the string "LOG" are stored as a list of file names (for example, NetshConfig.log, Logdat.svd, and Mylog.bat) in the Loglist.txt file. To use more than one filter in the same command, separate the filters with a pipe (|). For example, the following command searches every directory on drive C:, finds the file names that include the string "Log", and then displays them in one Command Prompt window at a time: dir c:\ /s /b | find "LOG" | more By using a pipe (|), you direct Cmd.exe to send the dir command output through the find filter command. The find command selects only file names that contain the string "LOG." The more command displays the file names that are selected by the find command, one Command Prompt window at a time. For more information about filter commands, see Using filters. ShellSpecifies the name and location of an alternate command interpreter you want Windows XP to use for the MS-DOS subsystem. Syntax shell=[[Drive:]Path] FileName [parameters] Parameters [[Drive:]Path] FileName Specifies the location and name of the command interpreter. parameters Specifies any command-line parameters or command-line options that can be used with the specified command interpreter. /? Displays help at the command prompt. Remarks Default setting By default, the MS-DOS subsystem uses a special version of Command.com that works seamlessly with the other Windows XP subsystems (including piping and redirection between subsystems); therefore, the shell command is unnecessary. Specifying a 16-bit command interpreter Although it is not recommended, you can use the shell command to specify your own 16-bit command interpreter. Using command-line options with a command interpreter The shell command itself does not accept any command-line options, but if the command interpreter does, you can include them on the shell command line. Examples Suppose the file Newshell.com is in the /Bin directory on your startup drive, and you want to use Newshell.com as your command interpreter. To do this, add the following command to your Config.nt file: shell=\bin\newshell.com -- Self taught user of Access 97 2003 with 7 years of experience with is part of 20 years of overall database experience. I'm still learning. "AA2e72E" wrote: Try this: Sub ListDir() Shell "CMD /C DIR C:\AJAY /S /B C:\MYFILES.TXT" End Sub The file C:\MYFILES.TXT will contain what you are after. "Ray" wrote: Does anyone have a VBA routine that would would print the name of each subdirectory and the contents of each of these directories into a text file? For example you would point it to a specified directory and the routine would locate each subdirectory and print the subdirectory name and its contents to a text file then locate the next subdirectory and print its contents etc, etc. The final output would list each subdirectory and all its contents. Thanks -- Ray |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Thu, 9 Jun 2005 10:26:15 -0700, "SacCourt"
wrote: Directory to a File Thank you AA2e72E this is simple elegant and powerful. Sub ListDir() Shell "CMD /C DIR C:\AJAY /S /B C:\MYFILES.TXT" End Sub Note that several commands are being nested. CMD calls up an instance of a Dos based window. DIR run the Directory command on C:\Ajay directory. The Directory command is implementing two switches /s to include files in all subdirectories /b to use the file bare. File bare omits directory headings, size, and date stamps. is a redirect which redirects theo output of the subsequent nested commands and switches to a file C:\myfiles.txt. The dos window closed upon execution, so the /C switch probably is a slash command for the CMD nesting. Subsequent to this you can run a transfer text routine to bring in the current directory data. This example worked with my modification the first time. This is a rare gift. Shell "CMD /C DIR p:\*.txt /S /B C:\MYFILES.TXT" In the past I had written a dos batch file to accomplish this. In addition the netuse command to map network unc paths to a drive letter before this command works. Bottom line: I will use the different dos based command switches to accomplish many different file and directory queries. Im upgrading to Windows XP from Windows 98. The NT directory Windows XP, NT, 2000, DIR and the Windows 95, 98, ME, 3.1 Dos DIR outputs are different. However, the /B swith for the bare file name may be consistent regardless of Dos command. Below is a paste of Unicode text of Microsoft Help files. They are copyrighted, however since this is a Microsoft site It should not matter. This is a Roseta stone for this type of work. Below you will find help for the command and switches as follows: CMD, DIR, Redirects and Pipes | Help Recitals CmdStarts a new instance of the command interpreter, Cmd.exe. Used without parameters, cmd displays Windows XP version and copyright information. Syntax cmd [[{/c|/k}] [/s] [/q] [/d] [{/a|/u}] [/t:fg] [/e:{on|off}] [/f:{on|off}] [/v:{on|off}] string] Parameters /c Carries out the command specified by string and then stops. /k Carries out the command specified by string and continues. /s Modifies the treatment of string after /c or /k. /q Turns the echo off. /d Disables execution of AutoRun commands. /a Creates American National Standards Institute (ANSI) output. /u Creates Unicode output. /t:fg Sets the foreground f and background g colors. The following tables lists valid hexadecimal digits that you can use as the values for f and g. Value Color 0 Black 1 Blue 2 Green 3 Aqua 4 Red 5 Purple 6 Yellow 7 White 8 Gray 9 Light blue A Light green B Light aqua C Light red D Light purple E Light yellow F Bright white /e:on Enables command extensions. /e:off Disables commands extensions. /f:on Enables file and directory name completion. /f:off Disables file and directory name completion. /v:on Enables delayed environment variable expansion. /v:off Disables delayed environment variable expansion. string Specifies the command you want to carry out. /? Displays help at the command prompt. Remarks Using multiple commands You can use multiple commands separated by the command separator && for string, but you must enclose them in quotation marks (for example, "command&&command&&command"). Processing quotation marks If you specify /c or /k, cmd processes the remainder of string and quotation marks are preserved only if all of the following conditions are met: You do not use /s. You use exactly one set of quotation marks. You do not use any special characters within the quotation marks (for example: &<( ) @ ^ |). You use one or more white-space characters within the quotation marks. The string within quotation marks is the name of an executable file. If the previous conditions are not met, string is processed by examining the first character to verify whether or not it is an opening quotation mark. If the first character is an opening quotation mark, it is stripped along with the closing quotation mark. Any text following the closing quotation marks is preserved. Executing registry subkeys If you do not specify /d in string, Cmd.exe looks for the following registry subkeys: HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun\REG_SZ HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun REG_EXPAND_SZ If either one or both registry subkeys are present, they are executed before all other variables. Caution Incorrectly editing the registry may severely damage your system. Before making changes to the registry, you should back up any valued data on the computer. Enabling and disabling command extensions Command extensions are enabled by default in Windows XP. You can disable them for a particular process by using /e:off. You can enable or disable extensions for all cmd command-line options on a computer or user session by setting the following REG_DWORD values: HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\EnableExtensions\REG_DWORD HKEY_CURRENT_USER\Software\Microsoft\Command Processor\EnableExtensions\REG_DWORD Set the REG_DWORD value to either 0ื1 (that is, enabled) or 0ื0 (that is, disabled) in the registry by using Regedit.exe. User-specified settings take precedence over computer settings, and command-line options take precedence over registry settings. Caution Incorrectly editing the registry may severely damage your system. Before making changes to the registry, you should back up any valued data on the computer. When you enable command extensions, the following commands are affected: assoc call chdir (cd) color del (erase) endlocal for ftype goto if mkdir (md) popd prompt pushd set setlocal shift start (also includes changes to external command processes) For more information about these commands, see Related Topics. Enabling delayed environment variable expansion If you enable delayed environment variable expansion, you can use the exclamation character to substitute the value of an environment variable at run time. Enabling file and directory name completion File and directory name completion is not enabled by default. You can enable or disable file name completion for a particular process of the cmd command with /f:{on|off}. You can enable or disable file and directory name completion for all processes of the cmd command on a computer or user logon session by setting the following REG_DWORD values: HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\CompletionChar\REG_DWORD HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\PathCompletionChar\REG_DWORD HKEY_CURRENT_USER\Software\Microsoft\Command Processor\CompletionChar\REG_DWORD HKEY_CURRENT_USER\Software\Microsoft\Command Processor\PathCompletionChar\REG_DWORD To set the REG_DWORD value, run Regedit.exe and use the hexadecimal value of a control character for a particular function (for example, 0ื9 is TAB and 0ื08 is BACKSPACE). User-specified settings take precedence over computer settings, and command-line options take precedence over registry settings. Caution Incorrectly editing the registry may severely damage your system. Before making changes to the registry, you should back up any valued data on the computer. If you enable file and directory name completion by using /f:on, use CTRL+D for directory name completion and CTRL+F for file name completion. To disable a particular completion character in the registry, use the value for white space [0ื20] because it is not a valid control character. When you press CTRL+D or CTRL+F, cmd processes file and directory name completion. These key combination functions append a wildcard character to string (that is, if one is not present), build a list of paths that match, and then display the first matching path. If none of the paths match, the file and directory name completion function beeps and does not change the display. To move through the list of matching paths, press CTRL+D or CTRL+F repeatedly. To move through the list backwards, press the SHIFT key and CTRL+D or CTRL+F simultaneously. To discard the saved list of matching paths and generate a new list, edit string and press CTRL+D or CTRL+F. If you switch between CTRL+D and CTRL+F, the saved list of matching paths is discarded and a new list is generated. The only difference between the key combinations CTRL+D and CTRL+F is that CTRL+D only matches directory names and CTRL+F matches both file and directory names. If you use file and directory name completion on any of the built-in directory commands (that is, CD, MD, or RD), directory completion is assumed. File and directory name completion correctly processes file names that contain white space or special characters if you place quotation marks around the matching path. The following special characters require quotation marks: & < [ ] { } ^ = ; ! ' + , ` ~ [white space] If the information that you supply contains spaces, use quotation marks around the text (for example, "Computer Name"). If you process file and directory name completion from within string, any part of the [Path] to the right of the cursor is discarded (that is, at the point in string where the completion was processed). Formatting legend Format Meaning Italic Information that the user must supply Bold Elements that the user must type exactly as shown Ellipsis (...) Parameter that can be repeated several times in a command line Between brackets ([]) Optional items Between braces ({}); choices separated by pipe (|). Example: {even|odd} Set of choices from which the user must choose only one Courier font Code or program output DirDisplays a list of a directory's files and subdirectories. Used without parameters, dir displays the disk's volume label and serial number, followed by a list of directories and files on the disk, including their names and the date and time each was last modified. For files, dir displays the name extension and the size in bytes. Dir also displays the total number of files and directories listed, their cumulative size, and the free space (in bytes) remaining on the disk. Syntax dir [Drive:][Path][FileName] [...] [/p] [/q] [/w] [/d] [/a[[:]attributes]][/o[[:]SortOrder]] [/t[[:]TimeField]] [/s] [/b] [/l] [/n] [/x] [/c] [/4] Parameters [Drive:][Path] Specifies the drive and directory for which you want to see a listing. [FileName] Specifies a particular file or group of files for which you want to see a listing. /p Displays one screen of the listing at a time. To see the next screen, press any key on the keyboard. /q Displays file ownership information. /w Displays the listing in wide format, with as many as five file names or directory names on each line. /d Same as /w but files are sorted by column. /a [[:] attributes] Displays only the names of those directories and files with the attributes you specify. If you omit /a, dir displays the names of all files except hidden and system files. If you use /a without specifying attributes, dir displays the names of all files, including hidden and system files. The following list describes each of the values you can use for attributes. The colon (:) is optional. Use any combination of these values, and do not separate the values with spaces. Value Description h Hidden files s System files d Directories a Files ready for archiving r Read-only files -h Files that are not hidden -s Files other than system files -d Files only (not directories) -a Files that have not changed since the last backup -r Files that are not read-only /o [[:]SortOrder] Controls the order in which dir sorts and displays directory names and file names. If you omit /o, dir displays the names in the order in which they occur in the directory. If you use /o without specifying SortOrder, dir displays the names of the directories, sorted in alphabetic order, and then displays the names of files, sorted in alphabetic order. The colon (:) is optional. The following list describes each of the values you can use for SortOrder. Use any combination of the values, and do not separate these values with white spaces. Value Description n In alphabetic order by name e In alphabetic order by extension d By date and time, earliest first s By size, smallest first g With directories grouped before files -n In reverse alphabetic order by name (Z through A) -e In reverse alphabetic order by extension (.ZZZ through .AAA) -d By date and time, latest first -s By size, largest first -g With directories grouped after files /t [[:]TimeField] Specifies which time field to display or use for sorting. The following list describes each of the values you can use for TimeField. Value Description c Creation a Last access w Last written /s Lists every occurrence, in the specified directory and all subdirectories, of the specified file name. /b Lists each directory name or file name, one per line, including the file name extension. /b does not display heading information or a summary. /b overrides /w. /l Displays unsorted directory names and file names in lowercase. /l does not convert extended characters to lowercase. /n Displays a long list format with file names on the far right of the screen. /x Displays the short names generated for files on NTFS and FAT volumes. The display is the same as the display for /n, but short names are displayed after the long name. /c Displays the thousand separator in file sizes. /4 Displays four-digit year format. /? Displays help at the command prompt. Remarks Using multiple filenames You can use multiple filenames. Separate file names with spaces, commas, or semicolons. You can use wildcard characters (that is, ? and *) in FileName to display a group of files. Using wildcards You can use wildcards (that is, ? and *) to display a list of a subset of files and subdirectories. Specifying file display attributes If you use /a with more than one value in attributes, dir displays the names of only those files with all the specified attributes. For example, if you use /a with r and -h for attributes by using either /a:r-h or /ar-h, dir displays only the names of read-only files that are not hidden. Specifying file name sorting If you specify more than one SortOrder value, dir sorts the file names by the first criterion first, then by the second criterion, and so on. For example, if you use /o with the e and -s values for SortOrder by using either /o:e-s or /oe-s, dir sorts the names of directories and files by extension, with the largest first, and then displays the final result. The alphabetic sorting by extension causes file names with no extensions to appear first, then directory names, and then file names with extensions. Using redirection symbols and pipes When you use a redirection symbol () to send dir output to a file or a pipe (|) to send dir output to another command, use /a:-d and /b to list the file names only. You can use FileName with /b and /s to specify that dir is to search the current directory and its subdirectories for all file names that match FileName. Dir lists only the drive letter, directory name, file name, and file name extension, one path per line, for each file name it finds. Before you use a pipe for redirection, you should set the TEMP environment variable in your Autoexec.nt file. Presetting dir parameters You can preset dir parameters by including set with the DIRCMD environment variable in your Autoexec.nt file. You can use any valid combination of dir parameters with set dircmd, including the location and name of a file. For example, to use the DIRCMD environment variable to set the wide display format (that is, /w) as the default format, type the following command in your Autoexec.nt file: set dircmd=/w For a single use of the dir command, you can override a parameter by using the DIRCMD environment variable. To do so, type the parameter that you want to override at the dir command prompt, preceding the parameter with a minus sign. For example: dir /-w To change the DIRCMD default settings, type: set=NewParameter The new default settings are effective for all subsequent dir commands until you use set dircmd again or until you restart your computer. To clear all default settings, type: set dircmd= To view the current settings of the DIRCMD environment variable, type: set Set displays a list of environment variables and their settings. For more information about setting environment variables, see Related Topics. The dir command, with different parameters, is available from the Recovery Console. Examples To display all directories, one after the other, in alphabetical order, in wide format and pausing after each screen, make sure that the root directory is the current directory, and then type: dir /s/w/o/p Dir lists the name of the root directory, the names of the subdirectories of the root directory, and the names of the files in the root directory, including extensions. Then, dir lists the subdirectory names and file names in each subdirectory in the tree. To alter the preceding example so that dir displays the file names and extensions, but omits the directory names, type: dir /s/w/o/p/a:-d To print a directory listing, type: ir prn When you specify prn, the directory list is sent to the printer attached to the LPT1 port. If your printer is attached to a different port, you must replace prn with the name of the correct port. You can also redirect output of the dir command to a file by replacing prn with a file name. You can also type a path. For example, to direct dir output to the file Dir.doc in the Records directory, type: dir \records\dir.doc If Dir.doc does not exist, dir creates it, unless the Records directory does not exist. In that case, the following message appears: File creation error To display a list of all the file names with the .txt extension in all directories on drive C, type: dir c:\*.txt /w/o/s/p Dir displays, in wide format, an alphabetized list of the matching file names in each directory and pauses each time the screen fills up, until you press a key to continue. Formatting legend Format Meaning Italic Information that the user must supply Bold Elements that the user must type exactly as shown Ellipsis (...) Parameter that can be repeated several times in a command line Between brackets ([]) Optional items Between braces ({}); choices separated by pipe (|). Example: {even|odd} Set of choices from which the user must choose only one Courier font Code or program output Using command redirection operatorsYou can use redirection operators to redirect command input and output streams from the default locations to different locations. The input or output stream location is referred to as a handle. The following table lists operators that you can use to redirect command input and output streams. Redirection operator Description Writes the command output to a file or a device, such as a printer, instead of the Command Prompt window. < Reads the command input from a file, instead of reading input from the keyboard. Appends the command output to the end of a file without deleting the information that is already in the file. & Writes the output from one handle to the input of another handle. <& Reads the input from one handle and writes it to the output of another handle. | Reads the output from one command and writes it to the input of another command. Also known as a pipe. By default, you send the command input (that is, the STDIN handle) from your keyboard to Cmd.exe, and then Cmd.exe sends the command output (that is, the STDOUT handle) to the Command Prompt window. The following table lists the available handles. Handle Numeric equivalent of handle Description STDIN 0 Keyboard input STDOUT 1 Output to the Command Prompt window STDERR 2 Error output to the Command Prompt window UNDEFINED 3-9 These handles are defined individually by the application and are specific to each tool. The numbers zero through nine (that is, 0-9) represent the first 10 handles. You can use Cmd.exe to run a program and redirect any of the first 10 handles for the program. To specify which handle you want to use, type the number of the handle before the redirection operator. If you do not define a handle, the default < redirection input operator is zero (0) and the default redirection output operator is one (1). After you type the < or operator, you must specify where you want to read or write the data. You can specify a file name or another existing handle. To specify redirection to existing handles, use the ampersand (&) character followed by the handle number that you want to redirect (that is, &handle#). For example, the following command redirects handle 2 (that is, STDERR) into handle 1 (that is, STDOUT): 1<&2 Duplicating handles The & redirection operator duplicates output or input from one specified handle to another specified handle. For example, to send dir output to File.txt and send the error output to File.txt, type: dirc:\file.txt 2&1 When you duplicate a handle, you duplicate all characteristics of the original occurrence of the handle. For example, if a handle has write-only access, all duplicates of that handle have write-only access. You cannot duplicate a handle with read-only access into a handle with write-only access. Redirecting command input (<) To redirect command input from the keyboard to a file or device, use the < operator. For example, to get the command input for the sort command from File.txt: sort<file.txt The contents of File.txt appear in the Command Prompt window as an alphabetized list. The < operator opens the specified file name with read-only access. As a result, you cannot write to the file when you use this operator. For example, if you start a program with <&2, all attempts to read handle 0 fail because handle 2 is initially opened with write-only access. Note Zero is the default handle for the < redirection input operator. Redirecting command output () Almost all commands send output to your Command Prompt window. Even commands that send output to a drive or printer display messages and prompts in the Command Prompt window. To redirect command output from the Command Prompt window to a file or device, use the operator. You can use this operator with most commands. For example, to redirect dir output to Dirlist.txt: dirdirlist.txt If Dirlist.txt does not exist, Cmd.exe creates it. If Dirlist.txt exists, Cmd.exe replaces the information in the file with the output from the dir command. To run the netsh routing dump command and then send the command output to Route.cfg, type: netsh routing dumpc:\route.cfg The operator opens the specified file with write-only access. As a result, you cannot read the file when you use this operator. For example, if you start a program with redirection &0, all attempts to write handle 1 fail because handle 0 is initially opened with read-only access. Note One is the default handle for the redirection output operator. Using the <& operator to redirect input and duplicate To use the redirection input operator <&, the file you specify must already exist. If the input file exists, Cmd.exe opens it as read-only and sends the characters contained in the file as input to the command as if they were input from the keyboard. If you specify a handle, Cmd.exe duplicates the handle you specify onto the existing handle in the system. For example, to open File.txt as input read to handle 0 (that is, STDIN), type: <file.txt To open File.txt, sort the contents and then send the output to the Command Prompt window (that is, STDOUT), type: sort<file.txt To find File.txt, and then redirect handle 1 (that is, STDOUT) and handle 2 (that is, STDERR) to the Search.txt, type: findfile file.txtsearch.txt 2<&1 To duplicate a user-defined handle 3 as input read to handle 0 (that is, STDIN), type: <&3 Using the & operator to redirect output and duplicate If you redirect output to a file and you specify an existing file name, Cmd.exe opens the file as write-only and overwrites the file's contents. If you specify a handle, Cmd.exe duplicates the file onto the existing handle. To duplicate a user-defined handle 3 into handle 1, type: &3 To redirect all of the output, including handle 2 (that is, STDERR), from the ipconfig command to handle 1 (that is, STDOUT), and then redirect the ouput to Output.log, type: ipconfig.exeoutput.log 2&1 Using the redirection operator to append output To add the output from a command to the end of a file without losing any of the information already in the file, use two consecutive greater than signs (that is, ). For example, the following command appends the directory list produced by the dir command to the Dirlist.txt file: dirdirlist.txt To append the output of the netstat command to the end of Tcpinfo.txt, type: netstattcpinfo.txt Using the pipe operator (|) The pipe operator (|) takes the output (by default, STDOUT) of one command and directs it into the input (by default, STDIN) of another command. For example, the following command sorts a directory: dir | sort In this example, both commands start simultaneously, but then the sort command pauses until it receives the dir command's output. The sort command uses the dir command's output as its input, and then sends its output to handle 1 (that is, STDOUT). Combining commands with redirection operators You can create custom commands by combining filter commands with other commands and file names. For example, you can use the following command to store the names of files that contain the string "LOG": dir /b | find "LOG" loglist.txt The dir command's output is sent through the find filter command. File names that contain the string "LOG" are stored as a list of file names (for example, NetshConfig.log, Logdat.svd, and Mylog.bat) in the Loglist.txt file. To use more than one filter in the same command, separate the filters with a pipe (|). For example, the following command searches every directory on drive C:, finds the file names that include the string "Log", and then displays them in one Command Prompt window at a time: dir c:\ /s /b | find "LOG" | more By using a pipe (|), you direct Cmd.exe to send the dir command output through the find filter command. The find command selects only file names that contain the string "LOG." The more command displays the file names that are selected by the find command, one Command Prompt window at a time. For more information about filter commands, see Using filters. ShellSpecifies the name and location of an alternate command interpreter you want Windows XP to use for the MS-DOS subsystem. Syntax shell=[[Drive:]Path] FileName [parameters] Parameters [[Drive:]Path] FileName Specifies the location and name of the command interpreter. parameters Specifies any command-line parameters or command-line options that can be used with the specified command interpreter. /? Displays help at the command prompt. Remarks Default setting By default, the MS-DOS subsystem uses a special version of Command.com that works seamlessly with the other Windows XP subsystems (including piping and redirection between subsystems); therefore, the shell command is unnecessary. Specifying a 16-bit command interpreter Although it is not recommended, you can use the shell command to specify your own 16-bit command interpreter. Using command-line options with a command interpreter The shell command itself does not accept any command-line options, but if the command interpreter does, you can include them on the shell command line. Examples Suppose the file Newshell.com is in the /Bin directory on your startup drive, and you want to use Newshell.com as your command interpreter. To do this, add the following command to your Config.nt file: shell=\bin\newshell.com |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Directory List
http://www.tushar-mehta.com/excel/so...ist/index.html Puts the results in an XL file, which can then be saved as a text file. Basic capability is free. Enhanced capabilities require purchase of a license. -- Regards, Tushar Mehta www.tushar-mehta.com Excel, PowerPoint, and VBA add-ins, tutorials Custom MS Office productivity solutions In article , says... Does anyone have a VBA routine that would would print the name of each subdirectory and the contents of each of these directories into a text file? For example you would point it to a specified directory and the routine would locate each subdirectory and print the subdirectory name and its contents to a text file then locate the next subdirectory and print its contents etc, etc. The final output would list each subdirectory and all its contents. Thanks |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks very much
"Tushar Mehta" wrote: Directory List http://www.tushar-mehta.com/excel/so...ist/index.html Puts the results in an XL file, which can then be saved as a text file. Basic capability is free. Enhanced capabilities require purchase of a license. -- Regards, Tushar Mehta www.tushar-mehta.com Excel, PowerPoint, and VBA add-ins, tutorials Custom MS Office productivity solutions In article , says... Does anyone have a VBA routine that would would print the name of each subdirectory and the contents of each of these directories into a text file? For example you would point it to a specified directory and the routine would locate each subdirectory and print the subdirectory name and its contents to a text file then locate the next subdirectory and print its contents etc, etc. The final output would list each subdirectory and all its contents. Thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
sub routine | Excel Discussion (Misc queries) | |||
Using (what goes in here) for sub routine | Excel Programming | |||
SUB ROUTINE | Excel Programming | |||
Routine?? | Excel Programming | |||
Need VBA Routine | Excel Programming |