VideoHelp Forum




+ Reply to Thread
Results 1 to 8 of 8
  1. Member Cheekie_Moonkie's Avatar
    Join Date
    Dec 2002
    Location
    United Kingdom
    Search Comp PM
    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.
    Quote Quote  
  2. (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)
    Quote Quote  
  3. VH Wanderer Ai Haibara's Avatar
    Join Date
    Jan 2006
    Location
    Somewhere on VideoHelp...
    Search Comp PM
    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?
    Quote Quote  
  4. VH Veteran jimmalenko's Avatar
    Join Date
    Aug 2003
    Location
    Down under
    Search PM
    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
    This can be saved anywhere.

    ******************************

    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
    Calls our VBS file. Reconfigure the path to point to the VBS file.
    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
    This file contains the directory names.
    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.
    Quote Quote  
  5. Member
    Join Date
    Mar 2002
    Location
    The Coal Region
    Search Comp PM
    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.
    Quote Quote  
  6. Member
    Join Date
    Jun 2004
    Location
    Victoria, Australia
    Search Comp PM
    Also, the Win2K / XP command line (CMD.EXE) can do it all itself.
    Code:
    FOR /F "delims=~" %f in (FolderList.txt) DO MD "%f"
    The tilde in the delims must be a character NOT found within any folder name (so text is a single line)

    Trev
    Quote Quote  
  7. Member Cheekie_Moonkie's Avatar
    Join Date
    Dec 2002
    Location
    United Kingdom
    Search Comp PM
    Originally Posted by TJohns
    Also, the Win2K / XP command line (CMD.EXE) can do it all itself.
    Code:
    FOR /F "delims=~" %f in (FolderList.txt) DO MD "%f"
    The tilde in the delims must be a character NOT found within any folder name (so text is a single line)

    Trev

    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)?
    Quote Quote  
  8. VH Veteran jimmalenko's Avatar
    Join Date
    Aug 2003
    Location
    Down under
    Search PM
    Originally Posted by Cheekie_Moonkie
    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.
    Start with putting the word "pause" (no quotes) in CreateDirectories.bat :
    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
    This will at least leave the info from the command window on the screen until you press any key to make it continue. Then you can view any possible error mkessages and post them here if you want to continue down this path.


    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"
    Worked very well !
    If in doubt, Google it.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!