Link to home
Start Free TrialLog in
Avatar of ScriptAddict
ScriptAddictFlag for United States of America

asked on

File in use VBS scripting question

Can anyone help me understand why this code isn't waiting for files to be released before trying to rename them?

For each objfile In files

'Test Code begins here

	on error resume next
	do
		Err.Clear
		Set fLog = objfso.OpenTextFile(objfile, ForAppending, false) 
	loop until Err.Number <> 70		
	on error goto 0

'End Test Code

	if right(objfso.getfilename(objfile),3) = "prn" then 
		objFSO.MoveFile objfile , folder.path & "\" & left(objfso.getfilename(objfile),len(objfso.getfilename(objfile))-3) & "pdf"
	end if
Next

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ScriptAddict

ASKER

I've used this code snipet before to determine if a file is in use.  I'm just going to change the <> 70 to <> 0, as this should be more robust.  

I'll repost if this doesn't fix it next week.
Your right I forgot my

Const ForReading = 1, ForWriting = 2, ForAppending = 8

row!

Thanks!
Avatar of Bill Prew
Bill Prew

Great, glad that helped!

~bp