ahmeddzcom Posted March 6, 2015 Share Posted March 6, 2015 Hello. i need move a file, But if the file exists rename. file(1) file(2) file(3) Tnx. Link to comment Share on other sites More sharing options...
markyrocks Posted March 6, 2015 Share Posted March 6, 2015 https://www.autoitscript.com/autoit3/docs/functions/FileMove.htm ahmeddzcom 1 Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning" Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 6, 2015 Moderators Share Posted March 6, 2015 (edited) Was that a request, a demand, or a question? Anyway, I just happened to have wrote something like this last week... lucky you. _myFileMove(@DesktopDir & "\test.au3", @DesktopDir & "\test.au3.bak", 16) Func _myFileMove($sSource, $sDestination, $iFlag = 0) ; $iFlag; $FC_NOOVERWRITEENUM = 16 ... This doesn't exist, so magic numbers are used Local $iRet If Not (BitAND($iFlag, 16) = 16) Then $iRet = FileMove($sSource, $sDestination, $iFlag) Return SetError(@error, @extended, $iRet) EndIf $iFlag = BitXOR($iFlag, 16) If Not FileExists($sDestination) Then $iRet = FileMove($sSource, $sDestination, $iFlag) Return SetError(@error, @extended, $iRet) EndIf Local $aParts = StringRegExp($sDestination, "^(.+?)(\.?\w+)\z", 3) Local $sFile, $iCC = 1 Do $sFile = $aParts[0] & "(" & $iCc & ")" & $aParts[1] $iCc += 1 Until Not FileExists($sFile) $iRet = FileMove($sSource, $sFile, $iFlag) Return SetError(@error, @extended, $iRet) EndFunc Edit: Forgot to enum my counter in the loop Edited March 6, 2015 by SmOke_N ahmeddzcom 1 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
mikell Posted March 6, 2015 Share Posted March 6, 2015 ? #include <File.au3> $source = @DesktopDir & "\test.au3" $myfolder = @DesktopDir & "\testdir\" $dest = $myfolder & "\test.au3" _myFileMove($source, $dest) Func _myFileMove($sSource, $sDestination) Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = "" Local $aPathSplit = _PathSplit($sDestination, $sDrive, $sDir, $sFilename, $sExtension) Local $iNum, $newfile = $sDestination While FileExists($newfile) $iNum += 1 $newfile = $sDrive & "\" & $sDir & "\" & $sFilename & " (" & $iNum & ")" & $sExtension Wend If FileMove($sSource, $newfile, 8) Then Return 1 EndFunc ahmeddzcom 1 Link to comment Share on other sites More sharing options...
AZJIO Posted March 6, 2015 Share Posted March 6, 2015 >_FO_GetCopyName My other projects or all Link to comment Share on other sites More sharing options...
ahmeddzcom Posted March 6, 2015 Author Share Posted March 6, 2015 Was that a request, a demand, or a question? Anyway, I just happened to have wrote something like this last week... lucky you. _myFileMove(@DesktopDir & "\test.au3", @DesktopDir & "\test.au3.bak", 16) Func _myFileMove($sSource, $sDestination, $iFlag = 0) ; $iFlag; $FC_NOOVERWRITEENUM = 16 ... This doesn't exist, so magic numbers are used Local $iRet If Not (BitAND($iFlag, 16) = 16) Then $iRet = FileMove($sSource, $sDestination, $iFlag) Return SetError(@error, @extended, $iRet) EndIf $iFlag = BitXOR($iFlag, 16) If Not FileExists($sDestination) Then $iRet = FileMove($sSource, $sDestination, $iFlag) Return SetError(@error, @extended, $iRet) EndIf Local $aParts = StringRegExp($sDestination, "^(.+?)(\.?\w+)\z", 3) Local $sFile, $iCC = 1 Do $sFile = $aParts[0] & "(" & $iCc & ")" & $aParts[1] $iCc += 1 Until Not FileExists($sFile) $iRet = FileMove($sSource, $sFile, $iFlag) Return SetError(@error, @extended, $iRet) EndFunc Edit: Forgot to enum my counter in the loop ? #include <File.au3> $source = @DesktopDir & "\test.au3" $myfolder = @DesktopDir & "\testdir\" $dest = $myfolder & "\test.au3" _myFileMove($source, $dest) Func _myFileMove($sSource, $sDestination) Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = "" Local $aPathSplit = _PathSplit($sDestination, $sDrive, $sDir, $sFilename, $sExtension) Local $iNum, $newfile = $sDestination While FileExists($newfile) $iNum += 1 $newfile = $sDrive & "\" & $sDir & "\" & $sFilename & " (" & $iNum & ")" & $sExtension Wend If FileMove($sSource, $newfile, 8) Then Return 1 EndFunc >_FO_GetCopyName iT's Working ... Tnx Link to comment Share on other sites More sharing options...
TheSaint Posted March 7, 2015 Share Posted March 7, 2015 You are indeed lucky, as I wouldn't have even been as illuminating as markyrocks, not without you having provided some basic code first. I wonder if you and other requestors realize just how lucky you are sometimes, at the brilliant helpers that provide at this forum? Akin to getting breakfast in bed. I do often wonder about the existence of the Help file and Wiki though, and what they are for. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
mikell Posted March 7, 2015 Share Posted March 7, 2015 (edited) TheSaint, You are totally right I had this code on hand though and a copy/paste with some minor modifs was less time consuming than providing explanations But it would probably have been different in case of an entire to-do script Getting breakfast in bed is like Xmas, it's very sweet while it occurs once a year Edited March 7, 2015 by mikell Link to comment Share on other sites More sharing options...
ahmeddzcom Posted March 8, 2015 Author Share Posted March 8, 2015 https://www.autoitscript.com/autoit3/docs/functions/FileMove.htm Did not see the answer. Sry My Brother ... Tnx. Link to comment Share on other sites More sharing options...
DXRW4E Posted March 8, 2015 Share Posted March 8, 2015 (edited) The thing is very complicated because of the file extension (that sometimes does not exist) etc etc, the safe way is _FileExistsEx '?do=embed' frameborder='0' data-embedContent>>; #FUNCTION# ==================================================================================================================== ; Name...........: _FileExistsEx ; Description ...: Get New Files Name ; Syntax.........: _FileExistsEx(ByRef $sFilePath[, $iFileExists]) ; Parameters ....: $sFilePath - The Fullpath file ; $iFileExists - Optional ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _FileExistsEx(ByRef $sFilePath, $iFileExists = 0) While FileExists($sFilePath) $iFileExists += 1 $sFilePath = StringRegExpReplace($sFilePath & " ", "( - \(\d+\))?(\.[^\.\\]*)?(\h)$", " - (" & $iFileExists & ")$2") WEnd EndFuncLocal $sFilePath = @DesktopDir & "\FileName1.xxx" _FileExistsEx($sFilePath) ;if the file exists - $sFilePath = @DesktopDir & "\FileName1 (1).xxx" _FileExistsEx($sFilePath, 7) ;if the file exists - $sFilePath = @DesktopDir & "\FileName1 (8).xxx"Ciao. Edited March 8, 2015 by DXRW4E ahmeddzcom 1 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