So I needed to copy all the file & folder names from a directory to save into a text file. I did so by using "DIR /B /O:N > filename.txt" in command prompt. Not only did it save all the file names inside the folders, but it added the directory location before all the names.
1. Is there someway to only save JUST the names of each file & folder inside that directory, without it saving the file names in each folder?
2. Is there someway that after the text file is created, to somehow remove the directory location before each name in the text? Can a script do this?
Thanks,
-Rich
Can you show a sample of what you have and how it should look after being processed?
"Not only did it save all the file names inside the folders, but it added the directory location before all the names." Not obvious how.
Moving right along...
You can lose some of the condusion by not flip-flopping between folder & directory.
=====================================
Life is too important to be taken seriously.M2
Judago, heres the example of what I have: C:\Users\Rich\Desktop\Movies\Weeds Season 2 Complete\Torrent downloaded from Demonoid.com.txt
C:\Users\Rich\Desktop\Movies\Weeds Season 2 Complete\Weeds.S02E01.HDTV.XviD-LOL.avi
C:\Users\Rich\Desktop\Movies\Weeds Season 2 Complete\Weeds.S02E02.HDTV.XviD.PROPER-hV.avi
C:\Users\Rich\Desktop\Movies\Weeds Season 2 Complete\Weeds.S02E03.HDTV.XviD-XOR.aviNotice it shows all the files inside the "Weeds Season 2 Complete" folder, when I would only like just the folder name ("Weeds Season 2 Complete") and not all the files inside. (There must be a command to add to "DIR /B /O:N > filename.txt" in the command prompt?)
Back to the reason of the topic; Is there someway (script maybe?) to remove the directory location text? Meaning to remove all the "C:\Users\Rich\Desktop\Movies\" before each line.
This way I only have just the names of the folders (and some file names) that are inside the 'Movies' folder.
I hope I cleared this up enough.
Thanks.P.S. Mechanix2Go - Sorry, but I'm not really understanding what you mean.
The reason I asked to see both what you have and what you want it to look like is because I was(and still am) confused as to the ultimate aim.
Do you just want the whole listing to look like:Weeds Season 2 Complete\Weeds.S02E03.HDTV.XviD-XOR.avi
I want it to look like this: Weeds Season 2 Complete
Another Movie Folder Name Here
And Another Movie Folder Name Here
And Even Another Movie Folder Name Here
and so on*Another Movie Folder Name Here* would be the name of a movie's folder. Because everything in the directory I want the names from are all movies, so I just want all the movie names saved to a text file like I have done, but I want it without the directory location and without all the files that may be contained inside the folders.
Hope this makes sense.
Ok ;) That should be fairly simple, it will be easier to just regenerate the list: Option 1:
(for /d %%a in ("C:\Users\Rich\Desktop\Movies\*") do @echo %%~na) > somefile.txtOption 2:
pushd "C:\Users\Rich\Desktop\Movies" dir /ad/on/b > somefile.txt popdOption 3:
(for /f "delims=" %%a in ('dir /b/on/ad "C:\Users\Rich\Desktop\Movies" ') do @echo %%~na) > somefile.txtIf you want to run Option 1 or Option 3 from the command line instead of a .bat script replace "%%" with "%" (half the percentage signs).
Sorry but I'm not advanced in this. Do I type those commands just as you typed them, into the command prompt? If so, I ran into this: %%a was unexpected at this time.
Edit: I tried option 1 with half the percentage signs, and it seemed to work (no errors or anything in command prompt) but somefiles.txt isn't in the folder.
I tried option 3 and I got "in was unexpected at this time"
A quirk of batch scripting is that for variables have a single percentage sign on the command line and two in a script: just copy and past this into the command prompt:
(for /d %a in ("C:\Users\Rich\Desktop\Movies\*") do @echo %~na) > somefile.txtEdit: I forgot the "@".
Are you sure the file isn't created? It should be the exact name it is output to "somefile.txt", no "s".
Also I forgot the @.
(for /d %a in ("C:\Users\Rich\Desktop\Movies\*") do @echo %~na) > somefile.txt It responds back with "More?" lol what does this mean?
It normally asks for "more?" when there is unmatched parens or quotes, this looks fine....
I think I have turned this into quite a mess ;) lets try to fix this simple issue.Try this and see if it outputs what you want:
dir /b/on/ad "C:\Users\Rich\Desktop\Movies";)
That worked perfect. Just a matter of copy&paste from command prompt. Thank you! It listed all the folder names inside my "Movies" folder. It didn't list the few files (.avi and .txt) that were in the folder but that's alright, theres only a couple of those.
Thank you, I appreciate all your time and help!
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |