program builder Posted March 13, 2010 Posted March 13, 2010 I am looking for autoit script, that will copy and paste files from a folder into another folder. Does anyone have a script for this?
99ojo Posted March 13, 2010 Posted March 13, 2010 Hi, have look at helpfile or have a search over forum: FileCopy () DirCopy () _FileListToArray () Try start coding. If you still have problems, come back with some code snippet. ;-)) Stefan
program builder Posted March 13, 2010 Author Posted March 13, 2010 (edited) I am trying to take all of the mp3 files from one folder, and put them in another would this work. $programfiles = ("c:/program files/ copyall ".mp3") $programfilesmusic = ("c:/program files/music/ pastall ".mp3") $copy = $programfiles $past = $programfilesmusic copyfile(($copy)) pastfile(($past)) I know this isn't the right code. But does anybody see what I am wanting to do? Edited March 13, 2010 by program builder
Yoriz Posted March 13, 2010 Posted March 13, 2010 (edited) You want to be looking at something more like $programfiles = "c:/program files/" $programfilesmusic = "c:/program files/music/" create a list of files of type ".mp3" inside $programfiles loop through each of the files in the list of files found while copying them from $programfiles each filename into $programfilesmusic each filename Edited March 13, 2010 by Yoriz GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
GEOSoft Posted March 13, 2010 Posted March 13, 2010 (edited) This is just intended to get you started down the right path. First of all it's backslash "\" in a folder path, not forward slash "/". It also helps to look up the functions in the help file to see what is actually happening. $sCopyFrom = "C:\Some\Folder\" $sCopyTo = "C:\Some\Other\Folder\" $hSearch = FileFindFirstFile($sCopyFrom & "*.mp3") If $hSearch <> -1 Then While 1 $sFile = FileFindNextFile($hSearch) If @Error Then ExitLoop If StringInStr(FileGetAttrib($sCopyFrom & $sFile), "D") Then DirCopy($sCopyFrom & $sFile, $sCopyTo & $sFile) Else FileCopy($sCopyFrom & $sFile, $sCopyTo & $sFile) EndIf WEnd EndIf Edited March 13, 2010 by GEOSoft 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!"
program builder Posted March 14, 2010 Author Posted March 14, 2010 ;I tryed this, but it didn't work. I tryed it with txt ;I put 2 text files into the text 1 and tryed to copy and ;past them into the text 2 folder ;here is the code I used $sCopyFrom = "C:\program files\text 1\" $sCopyTo = "C:\program files\text 2\" $hSearch = FileFindFirstFile($sCopyFrom & "*.txt") If $hSearch <> -1 Then While 1 $sFile = FileFindNextFile($hSearch) If @Error Then ExitLoop If StringInStr(FileGetAttrib($sCopyFrom & $sFile), "D") Then DirCopy($sCopyFrom & $sFile, $sCopyTo & $sFile) Else FileCopy($sCopyFrom & $sFile, $sCopyTo & $sFile) EndIf WEnd EndIf ;could someone tell me why it isn't working, when I run it?
dani Posted March 14, 2010 Posted March 14, 2010 (edited) You could also use this one: $sTarget = @ScriptDir & "\" & "temp" $sSource = @ScriptDir $sExt = "txt" MoveFiles($sSource, $sTarget, $sExt) Func MoveFiles($sSource, $sTarget, $sExt = ".*") If Not StringRegExp($sSource, "\\\z") Then $sSource &= "\" ; Append missing '\' to $sSource if needed If Not StringRegExp($sTarget, "\\\z") Then $sTarget &= "\" ; Append missing '\' to $sTarget if needed FileChangeDir($sSource) $hSearch = FileFindFirstFile("*.*") $hFile = FileFindNextFile($hSearch) While Not @error If @extended Then ; $hFile is a directory MoveFiles($sSource & $hFile, $sTarget, $sExt) ; Scan the subdirectory Else ; $hFile is a file FileChangeDir($sSource) If StringRegExp($hFile, "(?i)\." & $sExt & "\z") Then FileCopy($hFile, $sTarget, 8+1) ; Copy $hFile to $sTarget (create directory if needed and overwrite existing files -- flag 8+1) EndIf $hFile = FileFindNextFile($hSearch) WEnd FileClose($hSearch) EndFunc It is recursive -- it also moves files from subdirectories. If you don't want this, simply comment this line: MoveFiles($sSource & $hFile, $sTarget, $sExt) ; Scan the subdirectory Edited March 14, 2010 by dani
Yashied Posted March 14, 2010 Posted March 14, 2010 (edited) Another way. #Include <File.au3> _FileCopyEx('C:\Program Files\text 1', 'C:\Program Files\text 2', '*.txt') Func _FileCopyEx($sSrc, $sDest, $sMask = '*', $fReplace = 0) Local $FileList $FileList = _FileListToArray($sSrc, $sMask, 1) If Not @error Then For $i = 1 To $FileList[0] If (Not $fReplace) And (FileExists($sDest & '\' & $FileList[$i])) Then ContinueLoop EndIf If Not FileCopy($sSrc & '\' & $FileList[$i], $sDest & '\' & $FileList[$i], 9) Then Return 0 EndIf Next EndIf $FileList = _FileListToArray($sSrc, '*', 2) If Not @error Then For $i = 1 To $FileList[0] If Not _FileCopyEx($sSrc & '\' & $FileList[$i], $sDest & '\' & $FileList[$i], $sMask, $fReplace) Then Return 0 EndIf Next EndIf Return 1 EndFunc ;==>_FileCopyEx Edited March 14, 2010 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
GEOSoft Posted March 14, 2010 Posted March 14, 2010 @dani Using StringRegExp() the way you did to check for trailing backspaces seems like overkill ans abuse of StringRegExp(). A better method would be. Func MoveFiles($sSource, $sTarget, $sExt = ".*") $sSource = StringRegExpReplace($sSource, "(.+)\\?$", "$1\\") $sTarget = StringRegExpReplace($sTarget, "(.+)\\?$", "$1\\") Also did you test that code? I didn't but it looks all wrong, at least at a glance. @program builder Did you test to make sure the folders actually exist and that the script "sees" files in the source folder? Hint: MsgBox(0, "Result", $sFile) While 1 $sFile = FileFindNextFile($hSearch) If @Error Then ExitLoop MsgBox(0, "Result", $sFile) WEnd Did you check the help file for the functions I used to see what flags can be used with those functions? Did you bother to look for Dir*() functions in the help file? Did you look at the example code for the functions in the help file? 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!"
dani Posted March 14, 2010 Posted March 14, 2010 (edited) @dani Using StringRegExp() the way you did to check for trailing backspaces seems like overkill ans abuse of StringRegExp(). A better method would be. Func MoveFiles($sSource, $sTarget, $sExt = ".*") $sSource = StringRegExpReplace($sSource, "(.+)\\?$", "$1\\") $sTarget = StringRegExpReplace($sTarget, "(.+)\\?$", "$1\\") Also did you test that code? I didn't but it looks all wrong, at least at a glance. Hi Geo. Why is it abuse of StringRegExp? I don't really follow, as your StringRegExpReplace essentially does the same, but replaces it at the same time. It might be nicer as it's one command, but I am really not sure if it is more efficient seeing how your code always does a string replacement, while mine only does that if needed. My regular expression is easier, thus faster I think? Not sure how it's an overkill Anyway, of course I tested it, works perfectly. It's a bit different from the examples in the Help File, I tend to use this While Not @error instead of If @error Then ExitLoop etc. Also, @extended is a bit shorter than your StringInStr combined with FileGetAttrib to test whether the file is a directory. Edited March 14, 2010 by dani
GEOSoft Posted March 14, 2010 Posted March 14, 2010 (edited) What I meant by overkill was that If StringRight($s_Source, 1) <> "\" Then $s_Source &= "\" does the same as you did with the SRE (and probably faster). The other was just an example. Of course in this case we are talking milli-micro-seconds difference which is virtually no difference at all, I never worry about time differences that are shorter than the blink of an eye unless they are being called in a loop. What didn't look right had nothing to do with @Extended, it had to do with the positioning of the FileFindNextFile() line which is generally inside the loop. EDIT: of course mine wasn't right either because I forgot to close the search handle and yours was correct. I was just brain dead. Edited March 14, 2010 by GEOSoft 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!"
trancexx Posted March 14, 2010 Posted March 14, 2010 (edited) I don't get this. The guy is asking for code to copy mp3 files fom one location to some other (nothing more) and you are posting some uber-almost-cooking-coffee-recursive-300-level-fancy scripts. My advice to program builder is to read FileCopy related page in the help file, check for his permisions in the destination folder and change the nick name. Edited March 14, 2010 by trancexx ♡♡♡ . eMyvnE
Developers Jos Posted March 14, 2010 Developers Posted March 14, 2010 (edited) I would even go one steps further as far as an simple advice: Just open the helpfile for a change. For somebody that has shown much attitude it the past we can expect better than this .... right? Edited March 14, 2010 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
GEOSoft Posted March 14, 2010 Posted March 14, 2010 I would even go one steps further as far as an simple advice: Just open the helpfile for a change.Hmmmm, where have I read that before?Did you check the help file for the functions I used to see what flags can be used with those functions?Did you bother to look for Dir*() functions in the help file?Did you look at the example code for the functions in the help file?As we know, that's where most of the answers are if people would take the time to look. 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!"
dani Posted March 14, 2010 Posted March 14, 2010 (edited) True. I have once said most of the topics in General Help and Support would be obsolete if people would actually read the Help file. And I'm not talking about reading through it in 2 minutes but actually take the time, read some tutorials and practice some. Nevertheless; @program builder: you have enough input now so I'd recommend to either a | take one of the scripts provided and make sure to fully understand what they do and learn from them or b | take trancexx' suggestion and code something yourself. Btw I wouldn't call the scripts posted an overkill as trancexx does, they do only copy files from one directory to another so .. would be nice if they would make my cofee! Edited March 14, 2010 by dani
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