navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

Microsoft MVP

 

Help with VBS script

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Community >> Computer Software and Hardware issues >> Help with VBS script
Page: [1]
 
helpvb

 

Posts: 5
Joined: 10/3/2007
Status: offline

 
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
rdouglass

 

Posts: 9167
From: Biddeford, ME USA
Status: offline

 
RE: Help with VBS script - 10/3/2007 8:46:55   
Hi and Welcome to OutFront.

quote:

newname = left(filetorename,(divider-1)) & "_" & timestamp & "." & "txt"


Just a quick guess but have you tried something like this?

newname = left(filetorename,(divider-1)) & "_" & replace(timestamp,"/","_") & "." & "txt"

Or something like that? I suspect they're probably not renaming 'cause "/" is an illegal char in filenames and I don't see any place that they are being removed.

Hope it helps.

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to helpvb)
William Lee

 

Posts: 1041
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: Help with VBS script - 10/3/2007 8:50:39   
quote:

ORIGINAL: helpvb



divider = instr (filetorename,".")
newname = left(filetorename,(divider-1)) & "_" & timestamp & "." & "txt"





There is a space between instr and (filetorename,".")

Try join them up so it reads divider = instr(filetorename,".")

_____________________________

William Lee


(in reply to helpvb)
helpvb

 

Posts: 5
Joined: 10/3/2007
Status: offline

 
RE: Help with VBS script - 10/3/2007 9:02:04   
Thanks for the tip but still no luck, gives the same error message "Script encountered error. Error number: 5. Error description: Invalid procedure call or argument" in the log file.
I'm guessing its one small thing that is missing as the rest of the script runs fine.

Cheers.

(in reply to rdouglass)
William Lee

 

Posts: 1041
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: Help with VBS script - 10/3/2007 9:15:06   

What did the log file have to say? Is there any entries inside the log file?

_____________________________

William Lee


(in reply to helpvb)
helpvb

 

Posts: 5
Joined: 10/3/2007
Status: offline

 
RE: Help with VBS script - 10/3/2007 9:17:14   
Here is the output from the log file. Cheers

I: 03/10/2007 13:59:34 Renaming C:\Captureconfig\ASB_CAPTURE_Step1A to
I: 03/10/2007 13:59:34 Renaming C:\Captureconfig\ASP_cAPTURE_Step1A to
I: 03/10/2007 13:59:34 Renaming C:\Captureconfig\ASP_cAPTURE_Step1B to
I: 03/10/2007 13:59:34 Renaming C:\Captureconfig\ASP_cAPTURE_Step1C to
I: 03/10/2007 13:59:34 Renaming C:\Captureconfig\ASP_cAPTURE_Step2 to
E: 03/10/2007 13:59:34 Script encountered error. Error number: 5. Error description: Invalid procedure call or argument

(in reply to William Lee)
William Lee

 

Posts: 1041
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: Help with VBS script - 10/3/2007 9:20:15   

quote:

ORIGINAL: helpvb

Here is the output from the log file. Cheers

I: 03/10/2007 13:59:34 Renaming C:\Captureconfig\ASB_CAPTURE_Step1A to
I: 03/10/2007 13:59:34 Renaming C:\Captureconfig\ASP_cAPTURE_Step1A to
I: 03/10/2007 13:59:34 Renaming C:\Captureconfig\ASP_cAPTURE_Step1B to
I: 03/10/2007 13:59:34 Renaming C:\Captureconfig\ASP_cAPTURE_Step1C to
I: 03/10/2007 13:59:34 Renaming C:\Captureconfig\ASP_cAPTURE_Step2 to
E: 03/10/2007 13:59:34 Script encountered error. Error number: 5. Error description: Invalid procedure call or argument


Those filetorename does not have any file extensions!!

These files should at least have a "." followed by some extensions, usually 3 letters

_____________________________

William Lee


(in reply to helpvb)
helpvb

 

Posts: 5
Joined: 10/3/2007
Status: offline

 
RE: Help with VBS script - 10/3/2007 9:27:37   
Thanks, that was it. The files don't need an extenstion as they are SAN config files and only needed in case of DR.

Cheers.

(in reply to William Lee)
William Lee

 

Posts: 1041
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: Help with VBS script - 10/3/2007 9:30:40   

So, it is solved? thats it huh?

What is SAN and DR?

_____________________________

William Lee


(in reply to helpvb)
helpvb

 

Posts: 5
Joined: 10/3/2007
Status: offline

 
RE: Help with VBS script - 10/3/2007 9:38:45   
Our Storage Area Network and Disater Recovery.

Thanks again.

(in reply to William Lee)
William Lee

 

Posts: 1041
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: Help with VBS script - 10/3/2007 9:57:21   

quote:

ORIGINAL: helpvb

Our Storage Area Network and Disater Recovery.

Thanks again.


I see. Thanks for this info.

_____________________________

William Lee


(in reply to helpvb)
Page:   [1]

All Forums >> Community >> Computer Software and Hardware issues >> Help with VBS script
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts