Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 Delete/Move files with ActiveX

Author  Topic 

slugfest
Starting Member

18 Posts

Posted - 2004-10-29 : 11:36:47
I'm trying to use an ActiveX script to sort a number of files into a set of directories based on two characters (digits) of the file name. I can get them to sort fine if the script doesn't run across a file that already exists. So I tried adding a deleteFile to delete the existing file and then move the new file into that directory, but it keeps failing. Any advice is appreciated. Here's the script...

Function Main()

dir= "C:\_image_drop"
Set Fso = CreateObject("Scripting.FileSystemObject")
Set objFolder = Fso.GetFolder("C:\_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)
If Fso.FileExists(dir&"\"&n_dir&"\"&objFile) Then
Fso.DeleteFile(dir&"\"&n_dir&"\"&objFile)
End If
objFile.Move(dir&"\"&n_dir&"\")
End If
Next
End If

Main = DTSTaskExecResult_Success

End Function
   

- Advertisement -