File in use VBS scripting question

Posted on 2012-09-18
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
		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

Open in new window

Question by:ScriptAddict
    LVL 51

    Accepted Solution

    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

    LVL 11

    Author Comment

    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.
    LVL 11

    Author Closing Comment

    Your right I forgot my

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


    LVL 51

    Expert Comment

    by:Bill Prew
    Great, glad that helped!


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    So many times I have seen the words written in a question "if only I could show you" or " I know how hard it is for you since you can't see it" in any zone. That has inspired me to write about this tool in windows 7 called "Problem Steps Recorder…
    Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now