clicklogin1 Posted November 14, 2013 Share Posted November 14, 2013 (edited) everyday, i received many fixed .xls file. EX: abc mmm.xls, hhh klm.xls. lkj hgf.xls. I put all in a folder, ex:C:dailymail. i have many fixed folder with special name,.EX: mmm,klm,hgf...(a part of filename i received). everyday, i have to copy manual many file to many folder. EX: C:dailymailabc mmm.xls into mmm, C:dailymailhhh klm.xls into klm... can you help me do it automatically. Thanks so much. (My English is not good) update image: Edited November 21, 2013 by clicklogin1 Link to comment Share on other sites More sharing options...
kylomas Posted November 14, 2013 Share Posted November 14, 2013 clicklogin, 1 - Is the target folder always that part of the filename between a space and a period? e.g. c:testmy new dataset.xls target folder = "dataset" 2 - Are all of the files that you receive in a specific folder? 3 - If 2 is 'yes', then do you want to move all files everytime the automation runs? kylomas clicklogin1 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
clicklogin1 Posted November 14, 2013 Author Share Posted November 14, 2013 1. filename contain folder name. eg: folder i received many file. eg C:daily mail file name: data bush obama xxx.xls mail la ny xyz.xls ... target folder .eg "D:data mail" have many folder bush obama la ny ... i have to copy file "C:daily maidata bush obama xxx.xls" to folder "D:data mailbush obama" i have to copy file "C:daily maimail la ny xyz.xls" to folder "D:data mailla ny" note: xxx, xyz: random string thanks. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 14, 2013 Moderators Share Posted November 14, 2013 clicklogin and clicklogin1,You appear to have multiple accounts - this is not permitted here. I can merge them into a single account - which one do you wish to keep. M23 clicklogin1 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
clicklogin1 Posted November 14, 2013 Author Share Posted November 14, 2013 i am sory. clicklogin stolen password. i am using clicklogin1. thanks. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 14, 2013 Moderators Share Posted November 14, 2013 clicklogin1,No problem - the accounts have been merged as you will see if you refresh the page. M23 clicklogin1 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
clicklogin1 Posted November 19, 2013 Author Share Posted November 19, 2013 Can you help me? please! Link to comment Share on other sites More sharing options...
0xdefea7 Posted November 19, 2013 Share Posted November 19, 2013 This is untested, but might do what you want without making duplicates: #include <File.au3> $sPath = @HomeDrive & "\daily mai" $aFiles = _FileListToArray($sPath) $sBushObama = "D:\data mail\bush obama" $sLaNy = "D:\data mail\la ny" For $i = 0 To UBound($aFiles) - 1 If StringInStr($aFiles[$i], "Bush Obama") && Not FileExists($sBushObama & "\" & $aFiles[$i]) Then FileCopy($sPath & "\" & $aFiles[i], $sBushObama & "\" & $aFiles[$i]) If StringInStr($aFiles[$i], "la ny") && Not FileExists($sLaNy & "\" & $aFiles[$i]) Then FileCopy($sPath & "\" & $aFiles[i], $sLaNy & "\" & $aFiles[$i]) Next clicklogin1 1 Link to comment Share on other sites More sharing options...
MHz Posted November 20, 2013 Share Posted November 20, 2013 With the pattern in post #3, this code may do as requested. expandcollapse popup; set paths $source = 'C:\daily mail' $destination = 'D:\daily mail' ; check if paths exist For $1 In StringSplit($source & '|' & $destination, '|', 2); no count If Not FileExists($1) Then MsgBox(0x40030, @ScriptName, '"' & $1 & '" does not exist' & @CRLF) Exit 1 EndIf Next ; change to source directory If FileChangeDir($source) Then ; open a handle to find xls files $handle_find = FileFindFirstFile('*.xls') ; check if the handle is valid If $handle_find = -1 Then MsgBox(0x40030, @ScriptName, 'No xls files found') Exit 2 EndIf ; While 1 ; look for the next file $file_found = FileFindNextFile($handle_find) If @error Then ExitLoop ; check the file name with this pattern which returns the group in the name $folder = StringRegExpReplace($file_found, '\A\w{4} (.*) \w{3}\.xls\Z', '$1') ; if replacements occurred and folder is something If @extended And $folder Then ; if destination file exists then restart the loop If FileExists($destination & '\' & $folder & '\' & $file_found) Then ContinueLoop EndIf ; create the destination\folder If DirCreate($destination & '\' & $folder) Then ; copy the file to the destination\folder If Not FileCopy($file_found, $destination & '\' & $folder & '\') Then ConsoleWriteError('Failed to copy "' & $file_found & '"' & @CRLF) EndIf Else ConsoleWriteError('Failed to create folder "' & $folder & '"' & @CRLF) EndIf Else ConsoleWriteError('File "' & $file_found & '" did not match the pattern' & @CRLF) EndIf WEnd ; close the find xls files handle FileClose($handle_find) Else MsgBox(0x40030, @ScriptName, 'Unable to change working directory to "' & $source & '"' & @CRLF) EndIf clicklogin1 1 Link to comment Share on other sites More sharing options...
clicklogin1 Posted November 21, 2013 Author Share Posted November 21, 2013 thanks. update post 1. Link to comment Share on other sites More sharing options...
NewPlaza Posted November 21, 2013 Share Posted November 21, 2013 Are those folders the only 4 folders you will be working with? clicklogin1 1 Link to comment Share on other sites More sharing options...
MHz Posted November 21, 2013 Share Posted November 21, 2013 expandcollapse popup; set paths $source = 'C:\daily mail' $destination = 'D:\daily mail' ; set regex pattern which returns the folder in the group $pattern = '.*_(.*?)_\d+\.xls\Z' ; check if paths exist For $1 In StringSplit($source & '|' & $destination, '|', 2); no count If Not FileExists($1) Then MsgBox(0x40030, @ScriptName, '"' & $1 & '" does not exist' & @CRLF) Exit 1 EndIf Next ; change to source directory If FileChangeDir($source) Then ; open a handle to find xls files $handle_find = FileFindFirstFile('*.xls') ; check if the handle is valid If $handle_find = -1 Then MsgBox(0x40030, @ScriptName, 'No xls files found') Exit 2 EndIf ; While 1 ; look for the next file $file_found = FileFindNextFile($handle_find) If @error Then ExitLoop ; check the file name with this pattern which returns the group in the name $folder = StringRegExpReplace($file_found, $pattern, '$1') ; if replacements occurred and folder is something If @extended And $folder Then ; if destination file exists then restart the loop If FileExists($destination & '\' & $folder & '\' & $file_found) Then ContinueLoop EndIf ; create the destination\folder If DirCreate($destination & '\' & $folder) Then ; copy the file to the destination\folder If Not FileCopy($file_found, $destination & '\' & $folder & '\') Then ConsoleWriteError('Failed to copy "' & $file_found & '"' & @CRLF) EndIf Else ConsoleWriteError('Failed to create folder "' & $folder & '"' & @CRLF) EndIf Else ConsoleWriteError('File "' & $file_found & '" did not match the pattern' & @CRLF) EndIf WEnd ; close the find xls files handle FileClose($handle_find) Else MsgBox(0x40030, @ScriptName, 'Unable to change working directory to "' & $source & '"' & @CRLF) EndIf Updated to match clicklogin1 1 Link to comment Share on other sites More sharing options...
clicklogin1 Posted November 21, 2013 Author Share Posted November 21, 2013 thanks. script create new folder, but i need copy to exits folder. C:daily mail more than 4 .xls files (100+ files) eg: D:daily mail more than 4 folder (30+ folders) .xls files in C:daily mail many name. But a part string of file name is folder name in D:daily mail eg: C:daily mailsecret_canada money_sate bank_bush obama_2013.xls C:daily mailmail_acc dept_bush obama_11.xls 2 files above copy to D:daily mailhuman rightbush obama Link to comment Share on other sites More sharing options...
MHz Posted November 21, 2013 Share Posted November 21, 2013 I am not sure where you can get some of those folder names from so perhaps you need to set some FileCopy functions up manually. ; set paths $source = 'C:\daily mail' $destination = 'D:\daily mail' If FileChangeDir($source) Then FileCopy('*_nasa cia_*.xls', $destination & '\bussiness dept\nasa cia\', 8) FileCopy('*_white house_*.xls', $destination & '\bussiness dept\white house\', 8) FileCopy('*_bush obama_*.xls', $destination & '\human right\bush obama\', 8) FileCopy('*_ly na_*.xls', $destination & '\human right\ly na\', 8) ; FileCopy('*_folder name_*.xls', $destination & '\subject\folder name\', 8) Else MsgBox(0x40030, @ScriptName, 'Unable to change working directory to "' & $source & '"' & @CRLF) EndIf That is 4. You can follow the pattern with the other 30+ 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