CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2012
    Posts
    1

    Create folder from text file with VBscript

    I am trying to make a script that will read from a text file and create those folders. In my text file it contains:

    Code:
    C:\Users\Susan\Documents\iMacros\Downloads\(C82) [Imperial Chicken (Fujisaka Kuuki)] OZ (Neon Genesis Evangelion)[Decensored][English]
    C:\Users\Susan\Documents\iMacros\Downloads\(C82) [Hachiouji Kaipan Totsugeki Kiheitai (Makita Yoshiharu)] Just Want Moyashi! (Nisekoi, Raikkonen no Nettaigyo) (English)
    C:\Users\Susan\Documents\iMacros\Downloads\[Shimekiri Sanpunmae (Tsukimi Dai***u)] Ichika I'll Make You Feel Good (Infinite Stratos) (Eng) [Life4Kaoru]
    C:\Users\Susan\Documents\iMacros\Downloads\[Nakayohi Mogudan (Mogudan)] Gentei Omakehon 2005.2 (Neon Genesis Evangelion) [ENG] [LWB]
    C:\Users\Susan\Documents\iMacros\Downloads\(C82) [Kuronishiki (Takaharu)] A.Tsu.I.Yo.Ru (Touhou Project) [English] [CGrascal]
    C:\Users\Susan\Documents\iMacros\Downloads\(COMIC1☆6) [Dokuebi. (Antaresu 11)] Despair☠Pirates (Mouretsu Pirates) [English] =LWB=
    C:\Users\Susan\Documents\iMacros\Downloads\(C82) [Type-G (Ishigaki Takashi)] Ore to NanoFei to One Room (Mahou Shoujo Lyrical Nanoha StrikerS) [English] =TV + Afro=
    C:\Users\Susan\Documents\iMacros\Downloads\[Kesshoku Mikan] Cobalt Delphinium (English) (Resident Evil) {doujin-moe.us}
    C:\Users\Susan\Documents\iMacros\Downloads\[Clesta (Cle Masahiro)] CL-orz 23 (Kyoukai Senjou no Horizon) [English] [doujin-moe.us]
    C:\Users\Susan\Documents\iMacros\Downloads\(C82) [Number2 (Takuji)] Datte Aniki wa Nama Ecchi Suki damon (Ore no Imouto ga Konna ni Kawaii Wake ga Nai) [English] [PineApples R' Us + Doujin-Moe.us]
    C:\Users\Susan\Documents\iMacros\Downloads\(C82) [Number2 (Takuji)] Damette Ittemo Nakadashi Surundesuyone (Ore no Imouto ga Konna ni Kawaii Wake ga Nai) [English] [PineApples R' Us + Doujin-Moe.us]
    This is the script. Can anyone help me fix it?

    Code:
    dim objFileSys, objReadFile
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    
    Set objFileSys = CreateObject("Scripting.FileSystemObject")
    Set objReadFile = objFileSys.OpenTextFile("C:\Users\Susan\Documents\iMacros\Macros\file.txt", ForReading)
    
    Do until objReadFile.AtEndOfStream = True
        objFileSys.CreateFolder(objReadFile.ReadLine)
    
    Loop
    objReadFile.Close
    Set objReadFile = Nothing
    Set objFileSys = Nothing

  2. #2
    Join Date
    Jun 2009
    Posts
    113

    Re: Create folder from text file with VBscript

    Your script looks fine so I suspect the issue is either security (you don't have rights), or more likely nested folder names - so if you are trying to create a folder:
    c:\mainfolder\subfolder1\subsubfolder
    And you don't have a "c:\mainfolder\subfolder1" then it will fail with an error "path not found".
    The other issue might be characters that you can't have in a folder name:
    < > : " / \ | ? *
    I would suggest doing a search and replace on the text file for any of these.
    You can do what you want in a simple batch file though, because the MD command (or MKDIR) from the command prompt will create any intermediate folders. Here's a 2 line batch file that'll do what you want:
    Code:
    @echo off
    FOR /F "delims=¬" %%f IN ("C:\Users\Susan\Documents\iMacros\Macros\file.txt") DO md "%%f"
    Save this text to a file with a .BAT extension and double-click it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured