I know it is possible to create a series of directories using the "MD" command in a .bat file, like this:
md "My New Directory 1"
md "My New Directory 2"
md "My New Directory 3"
etc.
...but say I have a text file that reads:
My New Directory 1
My New Directory 2
My New Directory 3
etc.
(I.E. one directory name per line)
Does anyone know what I need to put in a .bat file so that that it would read a text file and create directories based on the text in each line of the text file?
Any help much appreciated here.
+ Reply to Thread
Results 1 to 8 of 8
-
-
(3rd edit)
Create a batch file in Notepad and save in the root of C:
md My_New_Directory_1 My_New_Directory_2 My_New_Directory_3
exit
This will create three new folders for you to use, the space in between the adds another folder.
So spaces indicate another "make directory" Use underscores for spaces.
Run from within Windows and your directories will be created.
I tried this from the desktop and it created new folders on the desktop even when I stipulated to use the C drive. (weird) -
As far as I remember, if the batch file above is anywhere in your PATH, it'll create those three directories in whatever directory you're calling it from. So, if C:\ is in your PATH, and you call it from C:\WINDOWS\Desktop\, you're going to get the three directories in \Desktop\.
To be sure, you should probably place a 'cd' command at the beginning, and change to the directory where you want the subdirectories to be created (if you want them to be created at the same spot each time the batch file is run).If cameras add ten pounds, why would people want to eat them? -
What about a batch file that uses a VBScript file to do the dirty work ?
******************************
CreateDirectories.vbs
Code:strSourceDir=wscript.arguments(0) Set WSHShell = WScript.CreateObject("WScript.Shell") Set objFileSystem = Wscript.CreateObject("Scripting.FileSystemObject") set inFile = objFileSystem.OpenTextFile (strSourceDir & "CreateDirectories.txt", 1, true) set outFile = objFileSystem.OpenTextFile (strSourceDir & "makedir.bat", 2, true) Do While Not inFile.AtEndOfStream outfile.WriteLine "md " & """" & strSourceDir & inFile.ReadLine & """" Loop infile.close outfile.close
******************************
CreateDirectories.bat
Code:rem Call VBS file and pass current working dir to it call "z:\Saved Batch Files\CreateDirectories.vbs" %~dp0 rem Call temp bat file makedir.bat call makedir.bat rem Clean up temp file del makedir.bat
Save this file to the folder where you want the directories created.
******************************
CreateDirectories.txt
Code:My New Directory 1 My New Directory 2 My New Directory 3
Save this file to the folder where you want the directories created.
******************************
How this works:
Put CreateDirectories.vbs in a safe place.
Create CreateDirectories.bat in your working directory and configure the correct path to CreateDirectories.vbs.
Create CreateDirectories.txt in your working directory.
Run CreateDirectories.bat.
Hints:
You can save CreateDirectories.bat to another safe place as once it is configured with the correct path, you only then need to copy and paste it into your working directory from now on - it does not require any ongoing changes.If in doubt, Google it. -
You could also search for "sed MS-DOS" and download it. You may consider saving in %systemroot%\system32 so sed is available from any directory in your system. The sed I have is named sed-3.59 (I renamed it to sed) and contains no installer.
Then, assuming your file of directories to create is named "myfiles.txt" and is in your current directory, you could issue:
sed -e "s/^/md \"/;s/$/\"/" myfiles.txt > newbat.bat
If you run the file "newbat" it will create the directories you want, with long file names, in the current directory.
AFAIK, MS-DOS cannot natively read text files nor will the non-EXE/COM commands accept pipes.
Good luck. -
Also, the Win2K / XP command line (CMD.EXE) can do it all itself.
Code:FOR /F "delims=~" %f in (FolderList.txt) DO MD "%f"
Trev -
Originally Posted by TJohns
Hi Trev,
Thanks for that. I stubled accross the FOR command last night, a couple of hours after posting, whilst trawling Wiki for information and I've come up with a similar line of script which seems to do the trick!
I also tried jimmalenko's suggestion, but I couldn't get it to work. CMD window appeared then dissapeared, but nothing happened. I know nothing about VBS, so I didn't know where to start looking to fix it.
Anyway, I'll continue working on a batch file containing the FOR command and, if anyone is interested, I'll post the result here (and possibly on my DVD>AVI guide)? -
Originally Posted by Cheekie_Moonkie
Code:rem Call VBS file and pass current working dir to it call "z:\Saved Batch Files\CreateDirectories.vbs" %~dp0 pause rem Call temp bat file makedir.bat call makedir.bat pause rem Clean up temp file del makedir.bat
Just FWIW I played with Trev's suggestion and got it working after a slight modification:
Code:FOR /F "delims=~" %%f in (test.txt) DO MD "%%f"
If in doubt, Google it.
Similar Threads
-
Batch "file creation from a text file, Placed into a created directory
By Muther in forum ProgrammingReplies: 5Last Post: 24th Sep 2015, 18:29 -
Bat file not looping?
By sambat in forum ComputerReplies: 5Last Post: 26th Feb 2011, 14:58 -
Need a .bat file to join avi files
By aat666 in forum Newbie / General discussionsReplies: 2Last Post: 7th Oct 2010, 06:46 -
Use text file to create chapters in DLP
By milway in forum Authoring (DVD)Replies: 4Last Post: 15th May 2008, 20:18 -
How to create subtitle file from transcript text file
By amagrace in forum SubtitleReplies: 7Last Post: 8th May 2008, 11:44