Automate the mundane for sanity sake (part 1)

I have read about a number of folks on the mymovies.name forum wanting to move individual files into dedicated folders but expressing concern about the repetative nature of this basic task.

Well with that in mind I put together a simple script that does just that, its been used by a few people without problem so I figured I would share with others so they could use it if they want too:

Dim FileSystem, szMovieFolder
szMovieFolder = "c:\test"
Set FileSystem = CreateObject("Scripting.FileSystemObject")

Dim Folder, File, Files, oMovieFolder, szFolderName, iEndOfShortFileName, szDestPath
Set oMovieFolder = FileSystem.GetFolder(szMovieFolder)

Set Files = oMovieFolder.Files

For Each File In Files
      ' is there a folder for this already?
      iEndOfShortFileName = InStr(1, File.Name, ".")
      szFolderName = Mid(File.Name, 1, iEndOfShortFileName -1)

      If (FileSystem.FolderExists(szFolderName)) = False Then
            ' nope lets make one
            szDestPath = szMovieFolder & "\" & szFolderName
            wscript.echo "Creating '" & szDestPath & "'"
            FileSystem.CreateFolder(szDestPath)
      End If

      ' ok lets move file
      wscript.echo "Moving '" & File.Name & "' to '" & szDestPath & "'"
      File.Move(szDestPath & "\" & File.Name)
Next

This is far from rocket science but a quick and dirty way to get the job done, hope it helps someone.

Print | posted on Monday, March 12, 2007 8:31 PM

Feedback


 re: Automate the mundane for sanity sake (part 1) 5/4/2007 3:22 PM raptor_demon

Hi,

great idea, but how do yourun this, n00b question i know but i dont have visual studio and i dont run iss so i cant use asp...

i guess im missing something.

thanks

Raptor


Gravatar

# re: Automate the mundane for sanity sake (part 1) 5/4/2007 3:35 PM Ryan

Just copy the script into a file called foo.vbs place it in the root of your folder with the files you want to move, and from a command prompt in that folder type "cscript foo.vbs"


Gravatar

 re: Automate the mundane for sanity sake (part 1) 5/8/2007 12:49 PM Peter

For Vista I had to repair some parts. This worked for me:

Dim FileSystem, szMovieFolder
szMovieFolder = "D:\My Videos"
Set FileSystem = CreateObject("Scripting.FileSystemObject")

Dim Folder, File, Files, oMovieFolder, szFolderName, iEndOfShortFileName, szDestPath
Set oMovieFolder = FileSystem.GetFolder(szMovieFolder)

Set Files = oMovieFolder.Files

For Each File In Files
' is there a folder for this already?
iEndOfShortFileName = InStrRev(File.Name, ".")
szFolderName = Mid(File.Name, 1, iEndOfShortFileName -1)
szDestPath = szMovieFolder & "\" & szFolderName

If Not FileSystem.FolderExists(szDestPath) Then
FileSystem.CreateFolder(szDestPath)
End If

' ok lets move file
' wscript.echo "Moving '" & File.Name & "' to '" & szDestPath & "'"
File.Move(szDestPath & "\" & File.Name)
Next

Title  
Name  
Email
Url
Comments   
Please add 7 and 7 and type the answer here: