Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ActiveX delete/move files

Status
Not open for further replies.

slugfest52

Programmer
Sep 1, 2004
2
US
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
 
Sounds like Fso.FileExists(f_current) is not returning TRUE when you expect it to. Have you checked the value you're passing to it? Add MsgBox(f_current) before the EXISTS and check it out. I think you need to modify the the line f_current = dir & "\" & n_dir & "\" & objFile. Good luck!

--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top