|
Answer» I am trying to find a way to write to file a list of all directories, sub-directories, and file names that are in those directories and sub directories without having to exclusively direct the DIR command to each physical directory of over 628 sub directories in that main directory. I am guessing there may be a way to make a FOR loop in a batch file when executed from a starting directory write to say a directory outside of that directory the appending file and folder contents without a CRC Error caused by trying to write back to location being used for DIR possibly sort of like the XCOPY CRC issue and using something similar to DIR>>Listing.txt to pass it appending to the Listing.txt file. But I am stumped on how to pass this DIR command to retrieve information for sub folders and its file contents as a wild card I guess you could call it to search and report back all without having to give it exact paths to follow deeper in and for all directories and subdirectories. Anyone have any code suggestions to make this happen?
I remember TREE way back giving info like this but was wondering if DIR can be tweaked to do this without having to grab TREE off of an old dos disk and seeing if it will behave under Windows 7 32bitI don't know if this helps...
Have you ever noticed the /S switch that DIR has?
Example:
I am interested in the folder S:\hyper-pi. Note I am in another (arbitrary) folder on another DRIVE.
1. bare listing
Code: [Select]F:\>dir s:\hyper-pi /s /b s:\hyper-pi\hyper_pi_0.99 s:\hyper-pi\hyper_pi_0.99\data00 s:\hyper-pi\hyper_pi_0.99\data01 s:\hyper-pi\hyper_pi_0.99\data02 s:\hyper-pi\hyper_pi_0.99\data03 s:\hyper-pi\hyper_pi_0.99\FreeImage.dll s:\hyper-pi\hyper_pi_0.99\HyperPI.exe s:\hyper-pi\hyper_pi_0.99\hyperpi_dll.dll s:\hyper-pi\hyper_pi_0.99\snapshots s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5 s:\hyper-pi\hyper_pi_0.99\data00\pi_data.txt s:\hyper-pi\hyper_pi_0.99\data00\pi_rec.dat2 s:\hyper-pi\hyper_pi_0.99\data01\pi_data.txt s:\hyper-pi\hyper_pi_0.99\data01\pi_rec.dat2 s:\hyper-pi\hyper_pi_0.99\data02\pi_data.txt s:\hyper-pi\hyper_pi_0.99\data02\pi_rec.dat2 s:\hyper-pi\hyper_pi_0.99\data03\pi_data.txt s:\hyper-pi\hyper_pi_0.99\data03\pi_rec.dat2 s:\hyper-pi\hyper_pi_0.99\snapshots\hpi_20110605_092830.png s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5\super_pi.hlp s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5\super_pi.txt s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5\super_pi_mod.exe 2. Full listing
Code: [Select] Volume in drive S is USB-1 Volume Serial Number is 2C51-AA7F
Directory of s:\hyper-pi
05/06/2011 09:15 <DIR> . 05/06/2011 09:15 <DIR> .. 05/06/2011 09:15 <DIR> hyper_pi_0.99 0 File(s) 0 bytes
Directory of s:\hyper-pi\hyper_pi_0.99
05/06/2011 09:15 <DIR> . 05/06/2011 09:15 <DIR> .. 05/06/2011 11:51 <DIR> data00 05/06/2011 11:51 <DIR> data01 05/06/2011 11:55 <DIR> data02 05/06/2011 11:52 <DIR> data03 10/01/2008 13:49 724,992 FreeImage.dll 13/02/2008 14:25 103,234 HyperPI.exe 12/02/2008 17:04 18,721 hyperpi_dll.dll 05/06/2011 09:28 <DIR> snapshots 05/06/2011 09:29 <DIR> super_pi_mod-1.5 3 File(s) 846,947 bytes
Directory of s:\hyper-pi\hyper_pi_0.99\data00
05/06/2011 11:51 <DIR> . 05/06/2011 11:51 <DIR> .. 05/06/2011 11:51 37,648,082 pi_data.txt 05/06/2011 11:55 48 pi_rec.dat2 2 File(s) 37,648,130 bytes
Directory of s:\hyper-pi\hyper_pi_0.99\data01
05/06/2011 11:51 <DIR> . 05/06/2011 11:51 <DIR> .. 05/06/2011 11:51 37,648,082 pi_data.txt 05/06/2011 11:55 48 pi_rec.dat2 2 File(s) 37,648,130 bytes
Directory of s:\hyper-pi\hyper_pi_0.99\data02
05/06/2011 11:55 <DIR> . 05/06/2011 11:55 <DIR> .. 05/06/2011 11:55 37,648,082 pi_data.txt 05/06/2011 11:55 48 pi_rec.dat2 2 File(s) 37,648,130 bytes
Directory of s:\hyper-pi\hyper_pi_0.99\data03
05/06/2011 11:52 <DIR> . 05/06/2011 11:52 <DIR> .. 05/06/2011 11:52 37,648,082 pi_data.txt 05/06/2011 11:55 48 pi_rec.dat2 2 File(s) 37,648,130 bytes
Directory of s:\hyper-pi\hyper_pi_0.99\snapshots
05/06/2011 09:28 <DIR> . 05/06/2011 09:28 <DIR> .. 05/06/2011 09:28 9,786 hpi_20110605_092830.png 1 File(s) 9,786 bytes
Directory of s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5
05/06/2011 09:29 <DIR> . 05/06/2011 09:29 <DIR> .. 23/09/1995 01:10 28,287 super_pi.hlp 23/09/1995 01:10 805 super_pi.txt 29/11/2005 20:16 104,960 super_pi_mod.exe 3 File(s) 134,052 bytes
Total Files Listed: 15 File(s) 151,583,305 bytes 23 Dir(s) 242,271,215,616 bytes free
You can use the /a-d switch to exclude the sub directory names (i.e. just list the files)
Code: [Select]F:\>dir s:\hyper-pi /s /b /a-d s:\hyper-pi\hyper_pi_0.99\FreeImage.dll s:\hyper-pi\hyper_pi_0.99\HyperPI.exe s:\hyper-pi\hyper_pi_0.99\hyperpi_dll.dll s:\hyper-pi\hyper_pi_0.99\data00\pi_data.txt s:\hyper-pi\hyper_pi_0.99\data00\pi_rec.dat2 s:\hyper-pi\hyper_pi_0.99\data01\pi_data.txt s:\hyper-pi\hyper_pi_0.99\data01\pi_rec.dat2 s:\hyper-pi\hyper_pi_0.99\data02\pi_data.txt s:\hyper-pi\hyper_pi_0.99\data02\pi_rec.dat2 s:\hyper-pi\hyper_pi_0.99\data03\pi_data.txt s:\hyper-pi\hyper_pi_0.99\data03\pi_rec.dat2 s:\hyper-pi\hyper_pi_0.99\snapshots\hpi_20110605_092830.png s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5\super_pi.GID s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5\super_pi.hlp s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5\super_pi.txt s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5\super_pi_mod.exe Code: [Select]F:\>dir s:\hyper-pi /s /a-d Volume in drive S is USB-1 Volume Serial Number is 2C51-AA7F
Directory of s:\hyper-pi\hyper_pi_0.99
10/01/2008 13:49 724,992 FreeImage.dll 13/02/2008 14:25 103,234 HyperPI.exe 12/02/2008 17:04 18,721 hyperpi_dll.dll 3 File(s) 846,947 bytes
Directory of s:\hyper-pi\hyper_pi_0.99\data00
05/06/2011 11:51 37,648,082 pi_data.txt 05/06/2011 11:55 48 pi_rec.dat2 2 File(s) 37,648,130 bytes
Directory of s:\hyper-pi\hyper_pi_0.99\data01
05/06/2011 11:51 37,648,082 pi_data.txt 05/06/2011 11:55 48 pi_rec.dat2 2 File(s) 37,648,130 bytes
Directory of s:\hyper-pi\hyper_pi_0.99\data02
05/06/2011 11:55 37,648,082 pi_data.txt 05/06/2011 11:55 48 pi_rec.dat2 2 File(s) 37,648,130 bytes
Directory of s:\hyper-pi\hyper_pi_0.99\data03
05/06/2011 11:52 37,648,082 pi_data.txt 05/06/2011 11:55 48 pi_rec.dat2 2 File(s) 37,648,130 bytes
Directory of s:\hyper-pi\hyper_pi_0.99\snapshots
05/06/2011 09:28 9,786 hpi_20110605_092830.png 1 File(s) 9,786 bytes
Directory of s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5
05/06/2011 09:29 8,628 super_pi.GID 23/09/1995 01:10 28,287 super_pi.hlp 23/09/1995 01:10 805 super_pi.txt 29/11/2005 20:16 104,960 super_pi_mod.exe 4 File(s) 142,680 bytes
Total Files Listed: 16 File(s) 151,591,933 bytes 0 Dir(s) 242,271,215,616 bytes freeYou can use the > operator to GET the whole DIR output (all the lines) to a fresh file; and >> to append the output to an existing file (if it exists, otherwise it will be created). I am not sure what you mean about CRC errors. The only thing that will happen, if you choose to redirect the DIR output to a file which is somewhere in the folder tree that you are examining, is that the output file will show up in the listing, unless you take steps (e.g. using | find /v) to exclude it. Because the file will not be CLOSED until after DIR has completed, if it is a new file it will show up in the full listing as having a size of zero bytes, and if it is a pre-existing file it will show the last size it had. But you can redirect the DIR output wherever you like.
Thanks Salmon for pointing me in the right direction. I forgot about that /S switch. Suppose next time I should /? and look at all options before posting a question
As far as the CRC error that I thought I WOULD get like xcopy, I guess I was thinking that if it was trying to write to file using > or >> while it was polling the directory that it could cause a loop back onto itself similar to xcopy which causes the CRC error. But your correct that it doesnt error out, it just shows it in listing.
|