Alternatives to deleting and renaming files. RRS feed

  • Question

  • Hi all,

    In a vbscript I get one error when deleting a file.

    The problem is that the script runs some dozens of times per day but just one or two times in a
    day the error happends and not every day.
    What I mean is I can't determine why and when it happends

    The file is a simple txt and I have to deleted before rename another file to reuse the name of the deleted file

    Additionally these files are on a local network share.

    My code:

    Set oSFile = CreateObject("Scripting.FileSystemObject")
    If oSFile.FileExists(NEWNAME) Then 
     oSFile.DeleteFile NEWNAME      <--Error in this line
    End If
    oSFile.MoveFile OLDNAME, NEWNAME

    Can someone suggest another wway to rename a file without error.


    Joao Simplicio Rodrigues

    Wednesday, September 18, 2019 8:46 AM

All replies

  • The most likely explanation is that the file is in use when you try to delete it.

    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Bill_Stewart Tuesday, April 14, 2020 4:52 PM
    Wednesday, September 18, 2019 2:01 PM
  • Well remembered.

    I had not even thought about that hypothesis.

    I'll have to see if that's it.

    Thank you.

    Joao Simplicio Rodrigues

    Thursday, September 26, 2019 1:30 PM