?
Solved

File in use VBS scripting question

Posted on 2012-09-18
4
Medium Priority
?
384 Views
Last Modified: 2012-09-18
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

0
Comment
Question by:ScriptAddict
  • 2
  • 2
4 Comments
 
LVL 59

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 38409972
Seemed to work okay for me, do you have ForAppending defined?

I would add a display of what the error code is if it still doesn't work.

  . . .
   Wscript.Echo Err.Number
   Wscript.Echo Err.Description
loop until Err.Number <> 70

~bp
0
 
LVL 11

Author Comment

by:ScriptAddict
ID: 38410027
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.
0
 
LVL 11

Author Closing Comment

by:ScriptAddict
ID: 38410062
Your right I forgot my

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

row!

Thanks!
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 38410567
Great, glad that helped!

~bp
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
While working, an annoying popup showing below will come and we cannot cancel or close it form the screen. The error message will come again and again.
This Micro Tutorial will give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question