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

Need correct syntax for script that moves all .X12 files to an archive

Status
Not open for further replies.

kdjonesmtb2

Technical User
Nov 19, 2012
93
US
Hello

I have a script that is generating the follwoing error when it tries to move .X12 files to an archive folder

File name example

qtptest1.X12
File already exists

Line (96): "fso.MoveFile f1,target".

However the Target archive folder does not have any files in it.

Thanks


If objRadioButton1.checked then
msgbox "You have selected the option to archive all text files"


Set fso=CreateObject("Scripting.FileSystemObject")
sour="\\ikanas267\Documents\kgittensjones\My Documents\QTP 834\Text files"
target="\\ikanas267\Documents\kgittensjones\My Documents\QTP 834\Archive"

Set fldr=fso.getFolder(sour)
for each file in fldr.files
if right(lcase(file.name),4)=".x12" then
call mover(lcase(file.path))
end if
next

sub mover(f1)
f2=replace(f1,"pdf","X12")
if fso.fileExists(f2) then
fso.MoveFile f1,target
fso.MoveFile f2,target
wscript.sleep 60000
end if
end sub



End if
 
Your quite welcome.

And thanks for the feedback. Now, other members with the same problem who find this thread will know that the solution worked.
 
Hi I spoke too soon. After a couple runs I started getting file exists errors for the target folder even when the target archive folder has no visible records

Is this a cache problem or memory issue in vbscript?

Do I need to check the date and time stamps of the files?

Thanks
 
What about:
Code:
sub mover(f1)
   f2=replace(f1,"pdf","X12")
   if fso.fileExists(f1) then fso.MoveFile f1, target
   if fso.fileExists(f2) then fso.MoveFile f2, target
   wscript.sleep 60000
end sub

Also shouldn't it be f2=replace(f1,"[highlight #FCE94F]X12[/highlight]","[highlight #FCE94F]pdf[/highlight]")
 
Hello

The revision to the code works great, however how could I add the ability to rename the archive files to give them unique names - like including an hour time stamp in the file name or some unique identifier?

thanks
 
Sure.

To do that, first extract the file name from its extension using GetBaseName, which is the filename without the extension, and GetExtensionName, which is the extension without the filename.

Then rebuild it with your date/time stamp info, which can be created from various vbsctipt date/time functions. Examples:
Year(Now())
Month(Now())
Day(Now())
Hour(Now())
Minute(Now())
Second(Now())
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top