Jump to content

Recommended Posts

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 post
Share on other sites

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 post
Share on other sites

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

 

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...