Creating directory lists for a range of folders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
daviddc114
Posts: 19
Joined: 23 Jul 2013 12:45

Creating directory lists for a range of folders

#1 Post by daviddc114 » 13 Sep 2013 05:47

okay, so i have a batch file that goes to specified directories and makes a .txt list of the files within the specified directory. I use the batch like so...

cd C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\`Step_One\Danny%1
for /F "delims=" %%j in ('dir /A-D /B /O:GEN') do echo %%~nj>> C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\`Step_One\Danny.txt

@echo off
cd C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\`Step_One\David%1
for /F "delims=" %%j in ('dir /A-D /B /O:GEN') do echo %%~nj>> C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\`Step_One\David.txt

@echo off
cd C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\`Step_One\Joe%1
for /F "delims=" %%j in ('dir /A-D /B /O:GEN') do echo %%~nj>> C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\`Step_One\Joe.txt

the only problem is now the peoples names are changing a lot, so i have to keep editing the batch file to match the names, and it is getting pritty crazy. Is there a way to modify this so it will just make a .txt list of whatever folder is in C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\`Step_One\

that way i do not have to specify a direct folder, it will just take whatever folder is in there and make a .txt file named the same name as the folder and have a list within it of all files in that folder. The list being /b (no extension or any other information ofcourse) just the name of the file itself.

thanks in advance :)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Almost there, Just a little more help pleeeeease :)

#2 Post by foxidrive » 13 Sep 2013 07:09

Test it on some sample folders first.

Code: Select all

@echo off
for /d %%a in ("C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\`Step_One\*") do (
   echo %%a
   del "%%a\%%~nxa.txt" 2>nul
      for /F "delims=" %%b in ('dir "%%a" /A-D /B /O:GEN') do >>"%%a\%%~nxa.txt" echo %%~nb
)
pause

daviddc114
Posts: 19
Joined: 23 Jul 2013 12:45

Re: Almost there, Just a little more help pleeeeease :)

#3 Post by daviddc114 » 13 Sep 2013 09:51

it did not work??
it returns the following in the CMD window...

C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\`Step_One\Charlie
File Not Found
C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\`Step_One\Danny
File Not Found
C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\`Step_One\David
File Not Found
Press any key to continue . . .

daviddc114
Posts: 19
Joined: 23 Jul 2013 12:45

Re: Almost there, Just a little more help pleeeeease :)

#4 Post by daviddc114 » 13 Sep 2013 09:57

wait, it actually does work, the only thing is it is putting the .txt in the folders themselves, i would like the .txt to be placed in "C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\`Step_One"

how would i modify it to do that?? thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Almost there, Just a little more help pleeeeease :)

#5 Post by foxidrive » 13 Sep 2013 19:02

This modification should put them all in the "`step_one" folder.

Code: Select all

@echo off
for /d %%a in ("C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\`Step_One\*") do (
   echo %%a
   del "%%~dpa\%%~nxa.txt" 2>nul
      for /F "delims=" %%b in ('dir "%%a" /A-D /B /O:GEN') do >>"%%~dpa\%%~nxa.txt" echo %%~nb
)
pause

daviddc114
Posts: 19
Joined: 23 Jul 2013 12:45

Re: Almost there, Just a little more help pleeeeease :)

#6 Post by daviddc114 » 16 Sep 2013 06:28

you are the man!!! thanks SOOOOO MUCH!!!

daviddc114
Posts: 19
Joined: 23 Jul 2013 12:45

Re: Almost there, Just a little more help pleeeeease :)

#7 Post by daviddc114 » 17 Sep 2013 06:57

one more question.. how do i modify it to go even one more level up in the directory tree to "C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures" ? thanks.. Dave.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Almost there, Just a little more help pleeeeease :)

#8 Post by foxidrive » 17 Sep 2013 07:11

And do what, Dave?

If you change the folder then it will process every folder under pictures, recursively, so it will process things like this:

C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\`Step_One\David
C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\`Step_One\Dave
C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\other folder\Jim
C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\other folder\Paul
C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\other folder\Dave

and the second dave folder will nuke the first file that was created by the first dave folder.

Explain what you need to do...

daviddc114
Posts: 19
Joined: 23 Jul 2013 12:45

Re: Almost there, Just a little more help pleeeeease :)

#9 Post by daviddc114 » 17 Sep 2013 08:19

I just want the .txt to be placed inC:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures

instead of
C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures/stepone

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Almost there, Just a little more help pleeeeease :)

#10 Post by foxidrive » 17 Sep 2013 08:52

It will do that now, if you change the path and remove the `Step_One but it will process all folders under pictures too. Is that what you want to do?

daviddc114
Posts: 19
Joined: 23 Jul 2013 12:45

Re: Almost there, Just a little more help pleeeeease :)

#11 Post by daviddc114 » 17 Sep 2013 09:23

no i dont want to delete stepone, i was just wanted it to place the .txt list in one folder up. You did it for me before, but i just cant seem to figure out what you changed in the batch file to get it to do it. its not a big deal if it cant be done, i was just wondering.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Almost there, Just a little more help pleeeeease :)

#12 Post by foxidrive » 17 Sep 2013 09:29

It's not as logical as changing what I changed before - batch files are speshul in some ways.

I needed to be sure of what you wanted to change. Try this: it moves the files back one folder after it has been created.

Code: Select all

@echo off
for /d %%a in ("C:\DaveCarbonesSchematicFinalizer\ProgramFiles\Pictures\`Step_One\*") do (
   echo %%a
   del "%%~dpa\%%~nxa.txt" 2>nul
      for /F "delims=" %%b in ('dir "%%a" /A-D /B /O:GEN') do >>"%%~dpa\%%~nxa.txt" echo %%~nb
   move /y "%%~dpa\%%~nxa.txt" .. >nul
)
pause

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Creating directory lists for a range of folders

#13 Post by foxidrive » 17 Sep 2013 09:34

Note that the subject topic has changed - please be descriptive.

Post Reply