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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why does this error out 1

Status
Not open for further replies.

szander

IS-IT--Management
Jan 23, 2003
16
0
0
US
'Rename Files using first 4 characters of name
Set FileObject = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = FileObject.GetFolder("C:\AP REGISTER\test\")
Set TargetFolder = FileObject.GetFolder("C:\AP REGISTER\test\archive\")
Set FileCollection = SourceFolder.Files

'Get the list of files
For each file in FileCollection
File.name = Left(File.name,4) + ".tif"
Next

I get file already exists error.

Thanks for the help
 
Since you have a target folder it looks like you are wanting to copy or move the files from the source to the target.

For each oFile in FileCollection
oFile.Copy("C:\AP REGISTER\test\archive\" & Left(File.name,4) & ".tif", True)
Next

 
Perhaps this ?
For each file in FileCollection
If LCase(Right(file.Name,4))<>".tif"
File.name=Left(File.name,InStrRev(file.Name,".")) & "tif"
End If
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I'm really not concerned with moving the files....i was using that to test with. Even so, I received this error when using Sheco example i get this....

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

H:\IT Temp\testscript.vbs(9, 82) Microsoft VBScript compilation error: Cannot use parentheses when calling a Sub

Exit code: 1 , 0001h
 
Oh, sorry. Either remove the parens like this:
oFile.Copy "C:\AP REGISTER\test\archive\" & Left(File.name,4) & ".tif", True


Or put the Call keyword in front like this:
Call oFile.Copy("C:\AP REGISTER\test\archive\" & Left(File.name,4) & ".tif", True)


 
That did the trick! Thanks much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top