theGnome Posted July 29, 2020 Share Posted July 29, 2020 Hey everyone I'm trying to get this script to copy images from one folder into another from a list that I have created and NOT skip the duplicates. In other words if there is two of the same image file on the list the script will only copy the image once and will ignore all other copies. Does anyone know how I can get it to produce the duplicate images from my list as well? print.au3 Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 29, 2020 Moderators Share Posted July 29, 2020 Your question is a bit vague. By duplicates, do you mean that if you have "My Dog.png" you want it to pick up "My Dog1", "My Dog2", "My Dog Sammy", etc.? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
theGnome Posted July 30, 2020 Author Share Posted July 30, 2020 I’m sorry about that. What I need is this. I have a list of orders 1.jpg 2.jpg 3.jpg 1.jpg 6.jpg whenever this script gets to the second 1.jpg file it skips it and doesn’t copy the image to the output file. I need it to catch all duplicates in case I have a lost with multiple part numbers that match. Thanks again for your time this has been so frustrating! Link to comment Share on other sites More sharing options...
pseakins Posted July 30, 2020 Share Posted July 30, 2020 Still not making much sense considering that Windoze does not support duplicate file names unless they are in separate folders. If so that would be a totally different kettle of fish. Phil Seakins Link to comment Share on other sites More sharing options...
Musashi Posted July 30, 2020 Share Posted July 30, 2020 9 hours ago, JLogan3o13 said: Your question is a bit vague ... 3 hours ago, pseakins said: Still not making much sense considering that Windoze does not support duplicate file names ... @theGnome : I would like to associate myself with the above comments. Your description is not very meaningful. 4 hours ago, theGnome said: I have a list of orders : 1.jpg 2.jpg 3.jpg 1.jpg 6.jpg (I suppose, you mean a list of file names - in this particular case images). How was this list created? It cannot be the result of e.g. _FileListToArray , because Windows, as mentioned by @pseakins, does not permit two identical file names in one folder. By the way : Should the list contain identical filenames, then these will be copied multiple times and overwrite an existing file in the target directory, but that would only be a performance issue. To avoid this, we need the initial list to remove multiple entries. The copying process itself is no big deal . "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Dan_555 Posted July 30, 2020 Share Posted July 30, 2020 (edited) If you really need to have the files copied over, then you can check if the file exists, and if it does, rename it, and then copy it. expandcollapse popup#include <String.au3> Opt("TrayIconDebug", 1) $S_running = "find-copy-photos" ;name the script If WinExists($S_running) Then MsgBox(0, "AutoIt", "The script to find and copy photos is already running") Exit EndIf AutoItWinSetTitle($S_running) $FileName = FileOpenDialog("Select the file that contains the list of photos to find & copy", "C:\temp\", "Text File (*.txt)") If @error Then Exit $FileNameArray = StringSplit(FileRead($FileName), @CRLF, 1) $PhotoFolder = FileSelectFolder("Select the top level folder that contains the photos.", "") If @error Then Exit $search = FileFindFirstFile($PhotoFolder & "\*.*") If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 Local $file = FileFindNextFile($search) If @error Then ExitLoop For $i = 1 To $FileNameArray[0] If $file = $FileNameArray[$i] Then Local $tmpnr = 0 Local $tmpf = _StringSearchSplit($file, ".", "R", "L", 0) ;Extract the filename Local $tmpe = _StringSearchSplit($file, ".", "R", "R", 1) ;Extract the extension Local $loop = 1 Local $file1=$file Do If FileExists(@DesktopDir & "\output\" & $file) Then $tmpnr = $tmpnr + 1 $file = $tmpf & "_(" & _StringRepeat("0", 4-StringLen($tmpnr)) & ")" & $tmpe If StringLen($tmpnr)>=5 then $loop=0 Else $loop = 0 EndIf Until $loop = 0 FileCopy($PhotoFolder & "\" & $file1, @DesktopDir & "\output\" & $file, 0) $FileNameArray[$i] = "" EndIf Next WEnd For $i = 1 To $FileNameArray[0] If $FileNameArray[$i] <> "" Then InputBox("Error", "Could not find:", $FileNameArray[$i]) If @error = 1 Then Exit EndIf Next Run("explorer.exe " & @DesktopDir & "\output\") Func _StringSearchSplit($str, $delimiter, $dir = "L", $ret = "R", $incdel = -1) ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringSearchSplit ; Description ...: Search for the first delimiter in a string, with searching direction, Case Sensitive search ; Syntax ........: _StringSearchSplit( $String, $delimiter [, $dir ] [, $ret ] [, $incdel ]) ; Parameters ....: $String - String to be checked. ; $delimiter - 1 char delimiter, has to be defined ; $dir - Search from direction (Left/Right), use "L" or "R" - Left is default ; The first letter will be used for direction, if multiple letters are entered e.g "Lab" = "L" ; $ret - Return side, Left or Right - Right is default. see above for valid entries. ; $incdel - Include delimiter 0 = No, 1 = Yes ; ; Return values .: Success - String ; ; e.g. 1: _StringSearch("c:\bat\test.bb","\","L","L") returns "c:" ; e.g. 2: _StringSearch("c:\bat\test.bb","\","L","L",1) returns "c:\" ; e.g. 3: _StringSearch("c:\bat\test.bb","\","L","R") returns "bat\test.bb" ; e.g. 4: _StringSearch("c:\bat\test.bb","\","L","R",1) returns "\bat\test.bb" ; e.g. 5: _StringSearch("c:\bat\test.bb","\","R","R") returns "test.bb" ; e.g. 6: _StringSearch("c:\bat\test.bb","\","R","R",1) returns "\test.bb" ; ; Failure - Empty string and @error flag as follows: ; @error : 1 - Empty String ; 2 - Delimiter should have a length of 1 char ; 3 - Should not happen, but if it does, search the PANIC button ! ; Author ........: Dan_555 (Autoitscript.com forum) ; =============================================================================================================================== Local $y Local $tmptxt = "" $dir = StringLeft(StringUpper($dir), 1) $ret = StringLeft(StringUpper($ret), 1) SetError(0) If StringLen($str) = 0 Then SetError(1) ;empty string Return "" EndIf If (StringInStr($str, $delimiter) = 0) Or (StringLen($delimiter) <> 1) Then SetError(2) ;invalid delimiter Return "" EndIf If $dir <> "L" And $dir <> "R" Then $dir = "L" ;Set default values If $ret <> "L" And $ret <> "R" Then $ret = "R" If $dir = "L" Then $y = StringInStr($str, $delimiter, 1) ;Search for the delimiter If $dir = "R" Then $y = StringInStr($str, $delimiter, 1, -1) If $incdel = 0 Then $incdel = -1 ;Tricky calculations ;) If $incdel <> -1 Then $incdel = 0 If $ret = "L" Then Return StringMid($str, 1, $y + $incdel) ;DisAssemble the string If $ret = "R" Then Return StringMid($str, $y - $incdel) SetError(3) Return "" EndFunc ;==>_StringSearchSplit P.S. I could not test the code above, but theoretically it should work. Edited July 30, 2020 by Dan_555 Bugfix Some of my script sourcecode Link to comment Share on other sites More sharing options...
theGnome Posted July 30, 2020 Author Share Posted July 30, 2020 Dan_555 thanks so much for your help. The list is created each day by me and at times can contain all individual image files or ten of the same one. your script works great but if it comes accross the same file more than 2 times it pops up an error saying it could not find the file even though it just made two copies of it. is there a way to make it create and rename the file as many times as it appears on the list? Link to comment Share on other sites More sharing options...
Dan_555 Posted July 30, 2020 Share Posted July 30, 2020 (edited) I have no material to test the script for errors. I could provide pictures, but i need the exact contents of the text file. Preferably the case where multiple files with the same name are present. I can only assume that the pictures are in many different folders, because no two files with the exact same name can be in the same folder, (luckily this is not linux, or imagine the confusion of 1.jpg, 1.Jpg 1.jPg and 1.jpG in the same folder) ... Then, the confusing part is $PhotoFolder = FileSelectFolder("Select the top level folder that contains the photos.", "") If you have a textfile with filenames, why do you need to select a top level folder ? Edited July 30, 2020 by Dan_555 Some of my script sourcecode Link to comment Share on other sites More sharing options...
theGnome Posted July 30, 2020 Author Share Posted July 30, 2020 currently my test list is basic but it pulls from a master print folder that contains many subfolders for different image groups. When it gets to the third instance of rg112.jpg a window pops up saying rg112.jpg could not be found and it doesn't make the third copy. I will include screen shots and the text file that I'm using for tests. rg111.jpg rg111.jpg rg112.jpg rg112.jpg rg112.jpg Thank you so much for your time, I have been trying to sort this out for longer than I'd like to admit haha Link to comment Share on other sites More sharing options...
Dan_555 Posted July 30, 2020 Share Posted July 30, 2020 (edited) Yes i see, i forgot to add the actual number, change the line $file = $tmpf & "_(" & _StringRepeat("0", 4-StringLen($tmpnr)) & ")" & $tmpe into $file = $tmpf & "_(" & _StringRepeat("0", 4-StringLen($tmpnr)) & $tmpnr &")" & $tmpe Edited July 30, 2020 by Dan_555 Some of my script sourcecode Link to comment Share on other sites More sharing options...
theGnome Posted July 30, 2020 Author Share Posted July 30, 2020 It's renaming the image files now but still giving me the same error when it comes to the third instance of the same image Link to comment Share on other sites More sharing options...
Dan_555 Posted July 30, 2020 Share Posted July 30, 2020 (edited) Ok, so you have a folder with the pictures, which contain RG111 to rg999, and you have a list, in which you need to duplicate the images according to the list, is that correct ? for example, if the list contains 4 of the RG444, then the same image(same folder) should be copied to the new folder as many times as in the list ? Edited July 30, 2020 by Dan_555 Some of my script sourcecode Link to comment Share on other sites More sharing options...
theGnome Posted July 30, 2020 Author Share Posted July 30, 2020 That is exactly what I need. Some days my list will be all unique numbers, other days it will have 50 of the same part number. I am sorry for any confusion this is all new to me.. Link to comment Share on other sites More sharing options...
theGnome Posted July 30, 2020 Author Share Posted July 30, 2020 Each morning I have to manually copy the images from the list to a folder. I'm hoping this will help me automate some of that and save me time each morning. Link to comment Share on other sites More sharing options...
Dan_555 Posted July 30, 2020 Share Posted July 30, 2020 (edited) Ok, i think it's working now: expandcollapse popup#include <String.au3> ;#include <Array.au3> Opt("TrayIconDebug", 1) $S_running = "find-copy-photos" ;name the script If WinExists($S_running) Then MsgBox(0, "AutoIt", "The script to find and copy photos is already running") Exit EndIf AutoItWinSetTitle($S_running) ;$FileName = "r:\Picturename.txt" $FileName = FileOpenDialog("Select the file that contains the list of photos to find & copy", "C:\temp\", "Text File (*.txt)") If @error Then Exit $FileNameArray = StringSplit(FileRead($FileName), @CRLF, 1) $PhotoFolder = FileSelectFolder("Select the top level folder that contains the photos.", "") ;$PhotoFolder = "r:\input\" If @error Then Exit $search = FileFindFirstFile($PhotoFolder & "\*.*") If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 Local $file = FileFindNextFile($search) $tmperr=@error If $tmperr Then ExitLoop For $i = 1 To $FileNameArray[0] If $file = $FileNameArray[$i] Then Local $tmpnr = 0 Local $tmpf = _StringSearchSplit($file, ".", "R", "L", 0) ;Extract the filename Local $tmpe = _StringSearchSplit($file, ".", "R", "R", 1) ;Extract the extension Local $loop = 1 Local $file1=$file Do If FileExists("r:" & "\output\" & $file1) Then $tmpnr = $tmpnr + 1 $file1 = $tmpf & "_(" & _StringRepeat("0", 4-StringLen($tmpnr)) & $tmpnr &")" & $tmpe If StringLen($tmpnr)>=5 then $loop=0 Else $loop = 0 EndIf Until $loop = 0 FileCopy($PhotoFolder & "\" & $file, "r:" & "\output\" & $file1, 0) $FileNameArray[$i] = "" EndIf Next WEnd ;_ArrayDisplay($FileNameArray) For $i = 1 To $FileNameArray[0] If $FileNameArray[$i] <> "" Then InputBox("Error", "Could not find:", $FileNameArray[$i]) If @error = 1 Then Exit EndIf Next ;Run("explorer.exe " & "r:" & "\output\") Run("explorer.exe " & @DesktopDir & "\output\") Func _StringSearchSplit($str, $delimiter, $dir = "L", $ret = "R", $incdel = -1) ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringSearchSplit ; Description ...: Search for the first delimiter in a string, with searching direction, Case Sensitive search ; Syntax ........: _StringSearchSplit( $String, $delimiter [, $dir ] [, $ret ] [, $incdel ]) ; Parameters ....: $String - String to be checked. ; $delimiter - 1 char delimiter, has to be defined ; $dir - Search from direction (Left/Right), use "L" or "R" - Left is default ; The first letter will be used for direction, if multiple letters are entered e.g "Lab" = "L" ; $ret - Return side, Left or Right - Right is default. see above for valid entries. ; $incdel - Include delimiter 0 = No, 1 = Yes ; ; Return values .: Success - String ; ; e.g. 1: _StringSearch("c:\bat\test.bb","\","L","L") returns "c:" ; e.g. 2: _StringSearch("c:\bat\test.bb","\","L","L",1) returns "c:\" ; e.g. 3: _StringSearch("c:\bat\test.bb","\","L","R") returns "bat\test.bb" ; e.g. 4: _StringSearch("c:\bat\test.bb","\","L","R",1) returns "\bat\test.bb" ; e.g. 5: _StringSearch("c:\bat\test.bb","\","R","R") returns "test.bb" ; e.g. 6: _StringSearch("c:\bat\test.bb","\","R","R",1) returns "\test.bb" ; ; Failure - Empty string and @error flag as follows: ; @error : 1 - Empty String ; 2 - Delimiter should have a length of 1 char ; 3 - Should not happen, but if it does, search the PANIC button ! ; Author ........: Dan_555 (Autoitscript.com forum) ; =============================================================================================================================== Local $y Local $tmptxt = "" $dir = StringLeft(StringUpper($dir), 1) $ret = StringLeft(StringUpper($ret), 1) SetError(0) If StringLen($str) = 0 Then SetError(1) ;empty string Return "" EndIf If (StringInStr($str, $delimiter) = 0) Or (StringLen($delimiter) <> 1) Then SetError(2) ;invalid delimiter Return "" EndIf If $dir <> "L" And $dir <> "R" Then $dir = "L" ;Set default values If $ret <> "L" And $ret <> "R" Then $ret = "R" If $dir = "L" Then $y = StringInStr($str, $delimiter, 1) ;Search for the delimiter If $dir = "R" Then $y = StringInStr($str, $delimiter, 1, -1) If $incdel = 0 Then $incdel = -1 ;Tricky calculations ;) If $incdel <> -1 Then $incdel = 0 If $ret = "L" Then Return StringMid($str, 1, $y + $incdel) ;DisAssemble the string If $ret = "R" Then Return StringMid($str, $y - $incdel) SetError(3) Return "" EndFunc ;==>_StringSearchSplit Func CW($txt) ConsoleWrite($txt & @crlf) EndFunc Edited July 30, 2020 by Dan_555 replacing my folders with original code Musashi 1 Some of my script sourcecode Link to comment Share on other sites More sharing options...
theGnome Posted July 30, 2020 Author Share Posted July 30, 2020 It works perfectly! Thank you so much for your help this is amazing!! 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