Windows – Command-Line folder structure on Windows

command-line-interfacedirectorywindows

I need to create a folder structure via command line, structure is as follows :

username > folder1 > folder2 > folder3 (and there are subdirectories within these folders as well)

This is a windows host, I have done "dir /ad > dir.txt (It outputs the parent folder)

Also, which command on dos would I use to create folder from text file ?

I have used xcopy /T /E (it fails at a certain point as the files are being read from these folders majority of the time), I have around 1500 folders and then sub-folders within these folders.

Best Answer

It's not realy clear what you want. Do you want to replicate a directory structure from one PC to the other and is there a connection between the host on which you created the textfile? If so, you can copy a directory structure without the files in it using the commandline:

robocopy [source] [destiantion] /Create

Or is it that you have a textfile with all the paths in it that you want to create. If so you might want to be creative with notepad. For example if you have a file that has the directories you want to create like:

c:\Users\john\dir1

Open the file with notepad. Press CTRL+H and replace 'C:' with 'MD C:'. Your file should look like this.

MD c:\Users\john\dir1

Now save the file as a batchfile (e.g. createfolder.cmd) and doubleclick it. It will create all the folders. If some directories contain spaces this will fail. You can paste all in excel in colmn B. In colmn A, add MD ", in colmn C add " select all and copy to notepad again. Now replace all Tab's with an empty string and save as a batchfile.

I hope it helps.

PS: If you are familiair withe to 'for' command this would be easier, but 'for' is indeed rather complicated.