Author Topic: FileRename Failure  (Read 89 times)

geauga

  • Newbie
  • *
  • Posts: 25
FileRename Failure
« on: February 28, 2019, 02:50:55 pm »
I have code that checks for the existence of a file.  If it exists it renames the file.  Later in my code I go to do a second FileRename that always fails with a System Error 183.  This error 183 is valid because the first FileRename fails.  The first FileRename give a system error 2 which say that the file does not exist.  It does exist.  From a security standpoint the first file has wide open security.  Any suggestions?

td

  • Tech Support
  • *****
  • Posts: 2770
    • WinBatch
Re: FileRename Failure
« Reply #1 on: March 01, 2019, 07:01:55 am »
It is very difficult to win an argument with a system error code.  You need to reconsider your assumptions and your script's logic.  Consider stepping through your script with the WinBatch Studio debugger while not making any assumptions about the contents of any variables or string literals.  The latter bit being the hard part. 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

kdmoyers

  • Full Member
  • ***
  • Posts: 242
Re: FileRename Failure
« Reply #2 on: March 04, 2019, 04:06:48 am »
I can add that if things are happening quickly, and the files are on a windows server, their current state can become muddled.  I can't tell you how many times I've had file update/rename/delete issues evaporate when I run a program one-line-at-time in the debugger.  Sometimes, a one second delay in the right spot makes the problems go away.

But first, you have to isolate the problem.  For this, the Studio debugger is a wonderful thing.  Huge time saver.
The mind is everything; What you think, you become.

td

  • Tech Support
  • *****
  • Posts: 2770
    • WinBatch
Re: FileRename Failure
« Reply #3 on: March 04, 2019, 07:47:03 am »
MSFT's SMB protocol has gone through several iterations over the last half-decade or so and those iterations have not always been implemented bug-free.  We have seen cases, where file manipulates like file deletes and moves are only respected on every other attempt when accessing files on Windows Server shares.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade