|
helpvb -> Help with VBS script (10/3/2007 6:36:29)
|
I have been giving a "Renaming" script but when I run it I get the following error "Invalid procedure call or argument". I don't know much about scripting and at an end of my knowledge. Can you let me know what or where its going wrong? It moves the files but doesn't rename. Thanks. On Error Resume Next const ForAppending = 8 const ForWriting = 2 'The following variabe contains the number of days to keep the files for. Default is 60. intOlderThan = 60 'The following variables are the paths to the files to be renamed and the archived files archivedirectory = "C:\CaptureConfig\archive\" tempdirectory = "C:\CaptureConfig\" 'The following variable calls the Datestamp function to create a unique suffix for the new file name timestamp = Datestamp() 'The following array contains the path to folder(s) which contain the files to be worked on. 'You can enter multiple folders. arrFolders = Array(archivedirectory) 'Bind to FileSystemObject and check for the existence of the logfile. If it exists then log file 'is opened for append, if it does not then it is created. Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists ("logfile.txt") Then Set outputfile = objFSO.OpenTextFile ("Logfile.txt", ForAppending) Else Set outputfile = objFSO.CreateTextFile ("Logfile.txt", ForWriting) End If 'The list of files in the tempdirectory is evaluated and then passed through a FOR..NEXT loop Set rootFolder = objFSO.GetFolder(tempdirectory) Set renameFiles = rootFolder.Files If objFSO.GetFolder(tempdirectory).Files.Count > 0 Then For Each filetorename in renameFiles 'The following variables are used to create the new name for the file divider = instr (filetorename,".") newname = left(filetorename,(divider-1)) & "_" & timestamp & "." & "txt" 'Check for the existence of the file to be renamed, rename it and append the timestamp If objFSO.FileExists (filetorename) Then WriteToLog "Renaming " & filetorename & " to " & newname , 4 objFSO.movefile filetorename , newname Else WriteToLog "File " & filetorename & " not found" , 2 Err.Raise(53) End If Next 'Move all of the files in the temp directory to the archived directory objFSO.movefile tempdirectory & "*.*" , archivedirectory Else Err.Raise(53) End If ErrorCheck Err.Number,Err.Description 'Work through the files in the folder defined by the arrFolders array 'Check to see if each is older than the number of days defined by the intDaysOld variable. 'If the file is older it is deleted and a record written to the log file For Each strPath in arrFolders Set objFolder = objFSO.GetFolder(Chr34&strPath&Chr34) Set colFiles = objFolder.Files For Each objFile In colFiles dateModified = objFile.DateLastModified intDaysOld = DateDiff("d", dateModified, Now) If intDaysOld > intOlderThan Then WriteToLog "Deleting file " & objfile , 4 objFile.Delete End If Next Next
|
|
|
|