madbull Posted February 5, 2008 Posted February 5, 2008 Wow haven't written/requested anything from the forum lately. Just a quick one. I used to be fammiliar with this but have forgotten it most likely. I need to use a batch file to create a text file containing the contentents of a folder. More basically put: Its a batch file/command that will tell me the contents of a folder and put it in a text file in a folder of my choosing. Thans in advance,
cluberti Posted February 5, 2008 Posted February 5, 2008 If you create a batch file that does a dir /s, and output it to a text file, it should be sufficient.dir /a /r /s x:\path\to\directory\you\want\listed\ > x:\path\to\text\file.txtThis will be all you need.
madbull Posted February 5, 2008 Author Posted February 5, 2008 (edited) If you create a batch file that does a dir /s, and output it to a text file, it should be sufficient.dir /a /r /s x:\path\to\directory\you\want\listed\ > x:\path\to\text\file.txtThis will be all you need.Thanks that's exactly what i needed. Thanks again,My other question is: Is there any way to create it or run another command etc so that the details wouldn't show, only the files.So instead of 30/01/2008 04:16 735,145,984 28 Weeks Later.aviit would be 28 Weeks Later Edited February 6, 2008 by madbull
Yzöwl Posted February 6, 2008 Posted February 6, 2008 It's just the /b switch you needdir/b/a/s "x:\path\to\directory\you\want\listed">"x:\path\to\text\file.txt"Or depending on what your output file is to be used for try this as a test:tree "%programfiles%" /f /a>.\desktop\output.txt
madbull Posted March 23, 2008 Author Posted March 23, 2008 It's just the /b switch you needdir/b/a/s "x:\path\to\directory\you\want\listed">"x:\path\to\text\file.txt"Or depending on what your output file is to be used for try this as a test:tree "%programfiles%" /f /a>.\desktop\output.txtThanks! Just what i needed,
JOSHSKORN Posted April 4, 2008 Posted April 4, 2008 dir/b/a/s "x:\path\to\directory\you\want\listed">"x:\path\to\text\file.txt"I saw this thread and wanted to ask a question on this. I'm new here, sorry if it's against the rules to ask a question from someone else's thread. I know some forums are like that.BASICALLY, I like what the above code does, however I only want to see the list of files I have, without the path and also without the extension. Example:Instead of seeing C:\Program Files\myfile.txt, I'd rather just see myfile.Is this possible w/ a batch file or do I need to use a different language (VB)?
IcemanND Posted April 5, 2008 Posted April 5, 2008 for /f %f in ('dir /s /a /b c:\winpe') do echo %~nfwill do it, keep in mind it will also give you the directories, replace c:\winpe with the directory you want the list from. If you want the results in a file add >>filename.txt to the end of the line.
JOSHSKORN Posted April 5, 2008 Posted April 5, 2008 for /f %f in ('dir /s /a /b c:\winpe') do echo %~nfwill do it, keep in mind it will also give you the directories, replace c:\winpe with the directory you want the list from. If you want the results in a file add >>filename.txt to the end of the line.Doesn't seem to work. It's not producing an output file. Here's what I'm using.for /f %f in ('dir /s /a /b "C:\Users\User1\Documents\Backup Files\Halo\Halo CE Maps\"') do echo %~nf >> C:\maplist.txt
IcemanND Posted April 5, 2008 Posted April 5, 2008 If you have it in a batch file double up the % signs %%fAnd with the space in the path you need this:for /f "delims=*" %f in ('dir /s /a /b "c:\users\user1\documents\backup files\halo\halo ce maps\"') do echo %~nf >> c:\maplist.txt
JOSHSKORN Posted April 5, 2008 Posted April 5, 2008 If you have it in a batch file double up the % signs %%fAnd with the space in the path you need this:for /f "delims=*" %f in ('dir /s /a /b "c:\users\user1\documents\backup files\halo\halo ce maps\"') do echo %~nf >> c:\maplist.txtYes it's in a batch file of course, hence the name of the thread. Anyway, the above code isn't the right answer, but modifying it based on your comment (adding the second '%'), was. This is what ended up working:for /f "delims=*" %%f in ('dir /s /a /b "C:\Users\user1\Documents\Backup Files\Halo\Halo CE Maps\"') do echo %%~nf >> c:\maplist.txtHere's a couple things I don't like.Is there a way to get it to run so you don't see the batch file outputting the data to the file on the screen?I noticed that if I run the file again, it appends. Instead, I'd prefer it to overwrite the existing file.
IcemanND Posted April 5, 2008 Posted April 5, 2008 @echo offecho.>maplist.txtfor /f "delims=*" %%f in ('dir /s /a /b "c:\users\user1\documents\backup files\halo\halo ce maps\"') do echo %%~nf >> c:\maplist.txtexit
JOSHSKORN Posted April 5, 2008 Posted April 5, 2008 @echo offecho.>maplist.txtfor /f "delims=*" %%f in ('dir /s /a /b "c:\users\user1\documents\backup files\halo\halo ce maps\"') do echo %%~nf >> c:\maplist.txtexitGot the first problem solved. However, the file is still being 'appended'. Let me make myself clear. When I run the batch file, it exports the list to the file, and if I run it a second and third time, what I end up with is two and three sets of the list, so if I have 300 files, running the batch file 2 and 3 times would make me end up with 600 and 900 items in the file. To get what I want, I have to manually delete maplist.txt and THEN run my batch file. So basically I need the file to be opened for input, not for append, if that sounds right.
IcemanND Posted April 5, 2008 Posted April 5, 2008 Sorry, forgot to put the path to maplist.txt in. change echo.>maplist.txt to echo.>c:\maplist.txt
JOSHSKORN Posted April 5, 2008 Posted April 5, 2008 Sorry, forgot to put the path to maplist.txt in. change echo.>maplist.txt to echo.>c:\maplist.txtOK that worked. Here's something I noticed. Why am I getting a blank line at the top of my file? Just wondering. Not a big issue, just a small annoyance. Here's what I'm using now based on your most recent reply:@echo offecho.>C:\maplist.txtfor /f "delims=*" %%f in ('dir /s /a /b "C:\Users\user1\Documents\Backup Files\Halo\Halo CE Maps\"') do echo %%~nf >> c:\maplist.txtexit
IcemanND Posted April 5, 2008 Posted April 5, 2008 the echo. puts the blank line, your other option would be to putif exist c:\maplist.txt del c:\maplist.txtwhich would delete the file so there would be nothing to append to.
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now