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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

samiam41Author Commented:
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?
samiam41Author Commented:
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..
samiam41Author Commented:
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?
robocopy.exe can actually do this in one take.
The syntax is a bit different than with usual copy commands, you specify source folder, destination folder (no files in these arguments), and it will by default copy everything in that folder.
Other arguments you need are
/xf *.* - exclude all files (we only want the dirs)
/e - copy subfolders, even if empty
/lev:2 - the level of subfolders to copy (1 is the source folder itself)
You might want to check robocopy.doc in the ResKit installation folder, it's a powerful tool.

Windows Server 2003 Resource Kit Tools
robocopy.exe "O:\ld\Directory\Departments" "N:\ew\Directory\Departments" /xf *.* /e /lev:2

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
samiam41Author Commented:
Dang that is AWESOME!  Just finished that task in under a second.  
samiam41Author Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.