slugfest52
Programmer
I have a directory full of image files. Inside that directory are also a slew of subdirectories. What I am trying to do is run an ActiveX script that...
1) Takes each image file
2) Finds its appropriate subdirectory (by last two digits of file name)
3) Checks to see if that image exists already in the subdirectory
4) If it does, it deletes the existing image
5) Then it moves the image to the proper subdirectory.
The sorting works fine if it doesn't run into an existing image. But if it does, it errors out with "file already exists". Here's the script.
Function Main()
dir= "C:\FTP\moreland\Htdocs\_image_drop"
Set Fso = CreateObject("Scripting.FileSystemObject")
Set objFolder = Fso.GetFolder("C:\FTP\moreland\Htdocs\_image_drop")
Set colFiles = objFolder.Files
If colFiles.Count > 0 Then
For each objFile in colFiles
If UCase(Right(objFile, 4)) = ".JPG" then
n_dir = Left(Right(objFile, 8), 2)
f_current = dir & "\" & n_dir & "\" & objFile
If Fso.FileExists(f_current) Then
Fso.DeleteFile f_current, True
End If
objFile.Move(dir & "\" & n_dir & "\")
End If
Next
End If
Main = DTSTaskExecResult_Success
End Function
1) Takes each image file
2) Finds its appropriate subdirectory (by last two digits of file name)
3) Checks to see if that image exists already in the subdirectory
4) If it does, it deletes the existing image
5) Then it moves the image to the proper subdirectory.
The sorting works fine if it doesn't run into an existing image. But if it does, it errors out with "file already exists". Here's the script.
Function Main()
dir= "C:\FTP\moreland\Htdocs\_image_drop"
Set Fso = CreateObject("Scripting.FileSystemObject")
Set objFolder = Fso.GetFolder("C:\FTP\moreland\Htdocs\_image_drop")
Set colFiles = objFolder.Files
If colFiles.Count > 0 Then
For each objFile in colFiles
If UCase(Right(objFile, 4)) = ".JPG" then
n_dir = Left(Right(objFile, 8), 2)
f_current = dir & "\" & n_dir & "\" & objFile
If Fso.FileExists(f_current) Then
Fso.DeleteFile f_current, True
End If
objFile.Move(dir & "\" & n_dir & "\")
End If
Next
End If
Main = DTSTaskExecResult_Success
End Function