goodbyeplanet Posted October 18, 2010 Share Posted October 18, 2010 I know how to use FileCopy to copy a single file from the current directory to another directory but how do i do it when i want to copy two files at once using a single line. for example how can i come up with a single line of code instead of 2 statements like below: FileCopy("C:\old\file1.exe", "C:\new\") FileCopy("C:\old\file2.exe", "C:\new\") Link to comment Share on other sites More sharing options...
water Posted October 18, 2010 Share Posted October 18, 2010 (edited) Why do you want to do it in a single line? Any problems with two lines? Maybe you can use wildcards. FileCopy("C:\old\file*.exe", "C:\new\") Edited October 18, 2010 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
goodbyeplanet Posted October 18, 2010 Author Share Posted October 18, 2010 (edited) Why do you want to do it in a single line? Any problems with two lines? Maybe you can use wildcards. Edited October 18, 2010 by goodbyeplanet Link to comment Share on other sites More sharing options...
water Posted October 18, 2010 Share Posted October 18, 2010 well hv been just trying to make things as simple as possible since it seems i will be copying and moving lots of files. so i thought if there was a way that would at least keep the code clean and not come up with a myriad of lines....unfortunately them wiildcards aint working tooHow do you get the filenames into your script?You could fill an array (read the list of files from an ini file, scan through the directory using FileFindFirstFile/FileFindNextFile etc.) and then copy them in a loop. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
GEOSoft Posted October 18, 2010 Share Posted October 18, 2010 Put the files into an array and then loop through the array. #Include<"file.au3"> $sPath = "C"\old\" $aFiles = _FileListToArray($sPath, "*.exe", 1) ;; << See the help file If NOT @Error Then For $i = 1 To UBound($aFiles) -1 If FileCopy($sPath & $aFiles[$i], "C:\New\" & $aFiles[$i], 9) = 0 Then ContinueLoop;; See the help file for the flags Next EndIf Also the example for FileCopy using wild cards should work for you. FileCopy("C:\old\*.*", "C:\new\", 9) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
goodbyeplanet Posted October 18, 2010 Author Share Posted October 18, 2010 (edited) you are so so sweet all of you..without this forum i wouldnt have made the progress i have made since morning..thanks it seems the array method stands to be the best, the wild card method for some reason skips some files....anywayz thanks again wonderful people Edited October 18, 2010 by goodbyeplanet Link to comment Share on other sites More sharing options...
water Posted October 18, 2010 Share Posted October 18, 2010 The wildcard method should not skip any files - if the wildcard is set properly. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
goodbyeplanet Posted October 18, 2010 Author Share Posted October 18, 2010 The wildcard method should not skip any files - if the wildcard is set properly.ok to be exact I have these files: france.exefrance_leys.exeI tried the wildcard method like this, FileCopy("france*.exe", "C:\new\") but it only copied the first one (france and left the other). One thing that i didnt state is that I also wouldnt want to copy all the files in the folder since there are some which i definitely dont want to be copied an dthat means a wildcard like this, FileCopy("*.exe", "C:\new\") or FileCopy("*.*", "C:\new\") would not be useful for me... Link to comment Share on other sites More sharing options...
water Posted October 18, 2010 Share Posted October 18, 2010 (edited) This code works fine for me. It creates a new directory if necessary and copies the files from the current directory. As result 1-0-0 is displayed. Could you please test it in your environment? $R = FileCopy("france*.exe","C:\new\",9) ConsoleWrite($R & "-" & @error & "-" & @extended & @CRLF) Edited October 18, 2010 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
goodbyeplanet Posted October 18, 2010 Author Share Posted October 18, 2010 (edited) This code works fine for me. It creates a new directory if necessary and copies the files from the current directory. As result 1-0-0 is displayed. Could you please test it in your environment? $R = FileCopy("france*.exe","C:\new\",9) ConsoleWrite($R & "-" & @error & "-" & @extended & @CRLF) oops Water, i feel a bit embarrassed here. Now its working exactly as u said I dont know why it only copied a single file before, probably its because i was working with a lot of code and i lost overview of what was happening..yes thanks again and that means i wil be much more comfortable with the wild card method instead of arraying. since it automatically creates a directory is it necessary for me to specify the DirCreate("C:\new\") before the code. here is my code: DirCreate("C:\new\") if @error Then exit FileCopy("france*.exe", "C:\new\") Edited October 18, 2010 by goodbyeplanet Link to comment Share on other sites More sharing options...
water Posted October 18, 2010 Share Posted October 18, 2010 Here is my code: DirCreate("C:\new\") if @error Then exit FileCopy("france*.exe", "C:\new\") Don't forget to check the returncode of FileCopy as well! It is good programming practive to do some error checking after commands that might fail. In your case the disk could run out of free space, some file attributes can make the overwriting impossible (according to the help filet) etc. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
GEOSoft Posted October 18, 2010 Share Posted October 18, 2010 Using the flag 9 (or 8) you don't have to create the folder in advance but it never hurts to do so. As I said above, read the help file to see what the flags are. Also, you could have still used the array method by making the same wildcard change in the second parameter of _FileListToArray() but the straight file copy works just as well. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
bahtea Posted October 28, 2010 Share Posted October 28, 2010 (edited) Why does this not work? $CopyThese = "C:\Temp\Willow.m3u" & "C:\Temp\Yellow.fpl" FileCopy($CopyThese, "D:\MMM\", 8) Nothing gets copied; only the D:\MMM folder's created. Edited October 28, 2010 by bahtea Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 28, 2010 Moderators Share Posted October 28, 2010 bahtea,First, please do not hijack threads. Second, FileCopy needs a single valid file path_name as a "source" parameter - what you are doing is passing it a combination (concatenation) of 2 such path_names. No wonder it gets confused! If you have a number of files to deal with, put them in an array and then loop through the array passing each one in turn.All clear? M23 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...
bahtea Posted October 28, 2010 Share Posted October 28, 2010 Sorry. I had no intention of hijacking. Since the topic is on "How do i copy 2 files at once" I had hoped that the kind of variable assigning I had done would be feasible. Partly because I was thinking of verifying later on the presence of the files being copied making use of such a variable. Yours is good advice, M23: I'll have to study the array aspect. Quite clear now on "FileCopy needs a single valid file path_name". Thanks. Link to comment Share on other sites More sharing options...
Varian Posted October 28, 2010 Share Posted October 28, 2010 I'm thinking you would have to run separate instances to copy 2 or more files at once. 2 or more scripts or 2 or more DOS copy calls (or some other copy operation) 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