Jump to content

Create Folders from File


 Share

Recommended Posts

I have a massive amount of files that I am trying to put into a certain directory structure. I have the file names in one text file and the directory name in the other. I am trying to read from both files and then move the corresponding file to the correct directory. The script is creating the directory structure fine, but it is not moving the files. Can someone check out this script and see what I am doing wrong.

Thank you

$dirlist = FileOpen("D:\termed041408\testdir.csv", 0)

$filelist = FileOpen("D:\termed041408\testlist.csv", 0)

$errorflag = 0

; Check if file opened for reading OK

 

If $dirlist = -1 Then

    MsgBox(0, "Error", "Unable to open directory file.")

    Exit

EndIf

 

If $filelist = -1 Then

    MsgBox(0, "Error", "Unable to open list of files.")

    Exit

EndIf

 

While 1

            $Dline = FileReadLine($dirlist)

            If @error = -1 Then ExitLoop

            $Pline = FileReadLine($filelist)

            DirCreate ("D:\termed041408\temp\" & $Dline & "\E-mail Data")

            DirCreate ("D:\termed041408\temp\" & $Dline & "\PC Drive Data")

            DirCreate ("D:\termed041408\temp\" & $Dline & "\Fileserver Data\H Drive")

            DirCreate ("D:\termed041408\temp\" & $Dline & "\Fileserver Data\Y Drive")

            FileMove ("D:\termed041408\temp\" & $Pline, "D:\termed041408\temp\" & $Dline & "\E-mail Data")

           ;If @error = -1 Then ExitLoop

Wend

 

FileClose($file)

FileClose($filelist)
Link to comment
Share on other sites

make sure the file actually exists. at D:\termed041408\temp\$pline destination.

Check out the FileExists() func if you wanna add some error checking.

Also, not a Big deal, but at the end you do a FileClose($file), I think you mean FileClose($dirlist)

Link to comment
Share on other sites

make sure the file actually exists. at D:\termed041408\temp\$pline destination.

Check out the FileExists() func if you wanna add some error checking.

Also, not a Big deal, but at the end you do a FileClose($file), I think you mean FileClose($dirlist)

Awesome thank you very much. The FileExists() Func allowed me to figure out that I was pointing into the wrong directory. I have it fixed now...
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...