Link to home
Start Free TrialLog in
Avatar of samiam41
samiam41Flag for United States of America

asked on

Dump list of existing folder names in a directory to txt file

Greetings Experts!  After receiving very credible advice, I will be changing the directory structure of my file server slightly to better accomodate our login script and to address security concerns.  I am most familiar with batch files and would ask that you supply your answer with such.

Here is the objective.  I have an existing directory called "Departments" which contains sub-folders named after each department in our company (15 departments in all).  What I would like to do is run a script to dump the names of each folder into a text file so that I can create the folders with the same names in a new directory.  Your help is appreciated.

Not sure if it helps or not but the environment a mix of windows xp/2003 in an AD environment.
Avatar of snagsy1980
snagsy1980
Flag of United Kingdom of Great Britain and Northern Ireland image

Avatar of jamesEE
jamesEE

Hello - you can run the following from a run command to output all the folder names to a text file:

Go start, Run, type cmd - ENTER.

dir <drive/sharename>:\ >> c:\folderlist.txt

Example: dir c:\windows >> c:\folderlist.txt

This will output all the folders within the windows directory to a text file called folderlist.txt in your c:\ drive
You can also use XCOPY with the /T and /E switches to copy a folder structure without copying any files.
Avatar of samiam41

ASKER

I like the xcopy option.  I ran the /? to dump the syntax commands but wasn't sure if there was a way to copy only the top level folders, not any of the subdirectories.  I also don't want to copy any data.

jamesEE- your option seemed to be the easiest but how do I create the folders once I have that txt file?
I thought this would do just the top level folders.  Why am I getting the subdirectories?
c:\>xcopy /t \\server\folder \\server\newfolder

Open in new window

Hi again! You said you wanted to dump the folder names into a text file - well thats what the command I suggested will do for you. As for recreating them - it's gonna be a case of File, New, Folder...

Unless you go with samiam41's rather neat (I thought) suggestion to copy the folders without the content, and then delete any subdirectories you dont need. This would probably be your best option..
jamesEE-  Thanks for the update.  Shift-3 came up with the xcopy suggestion and I am trying to perfect it.  The problem is that where I am copying the folders from, that directory has an enormous amount of subfolders which will be a pain in the @ss to go through.  I was hoping the /t option would do just the top level but no dice (or I am doing it wrong).

Also, can I use the mkdir option with the text file containing the folder names?
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dang that is AWESOME!  Just finished that task in under a second.  
You are unbelievable!  Seriously, you have to be some kind of prodigy.  Are you a contractor, just curious?  Thanks so much for the help, again!  Take care.