Champak Posted November 26, 2021 Share Posted November 26, 2021 Help me understand the error logic of file move because it's not making sense to me and I'm unable to figure an alternative. If I'm renaming a file, that would mean the destination does not exist because it's a new name in that directory. Why do I get an error of 0 then? I would think if I'm renaming a file to a new name then it would be a success value 1. Or is this thing looking at the fact that the source file itself already exists so that's why I'm getting the error? What I'm trying to do is upon failure of renaming the file, if the new name exists to rename it to something else....same name with a numerical extension. But the error logic is messing this up. Any help? Link to comment Share on other sites More sharing options...
Danp2 Posted November 26, 2021 Share Posted November 26, 2021 Where are the files located (local disk, network share, etc)? Have you confirmed that you have sufficient rights to create / rename a file? Can you post a short script that demonstrates the issue? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Champak Posted November 26, 2021 Author Share Posted November 26, 2021 It happens both on the desktop and mapped shared drive. If the file is renaming wouldn't that mean I have the rights? $sBasePath = "F:\Home Videos 2nd\" $sRenameFile = "test 2.mp4" $NewPath = "F:\Home Videos 2nd\testChange.mp4" $NewPathERROR = "F:\Home Videos 2nd\testChange_1.mp4" FileMove($sBasePath & $sRenameFile, $NewPath) If @error = 0 Then ConsoleWrite("! Rename - " & $NewPathERROR & " - " & @error & @CRLF) FileMove($sBasePath & $sRenameFile, $NewPathERROR, 1) ConsoleWrite("> Rename - " & $NewPathERROR & " - " & @error & @CRLF) EndIf Link to comment Share on other sites More sharing options...
Danp2 Posted November 26, 2021 Share Posted November 26, 2021 I think your mistake is that you are checking @error instead of the return value from the function call. Try this -- $sBasePath = "F:\Home Videos 2nd\" $sRenameFile = "test 2.mp4" $NewPath = "F:\Home Videos 2nd\testChange.mp4" $NewPathERROR = "F:\Home Videos 2nd\testChange_1.mp4" $iResult = FileMove($sBasePath & $sRenameFile, $NewPath) If Not $iResult Then ConsoleWrite("! Rename - " & $NewPath & " - " & $iResult & @CRLF) $iResult = FileMove($sBasePath & $sRenameFile, $NewPathERROR, 1) ConsoleWrite("> Rename - " & $NewPathERROR & " - " & $iResult & @CRLF) EndIf JockoDundee 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Champak Posted November 27, 2021 Author Share Posted November 27, 2021 That did it. Don't know why I overlooked I was mixing the two. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now