sciosalvi Posted January 19, 2014 Share Posted January 19, 2014 Hey guys! Quick question. As the output of a command (dir /b /s *.*) I get a list of files with their full path. How do I copy them to a folder? I've tried "file copy", I assume I need to get on a loop and start reading line by line until I get to the end of the var, but I can't figure out how to do it, I'm pretty green still. Thanks! Link to comment Share on other sites More sharing options...
Chimaera Posted January 19, 2014 Share Posted January 19, 2014 For $i = 1 To $aMyfilelist[0] FileCopy(@ScriptDir & '\' & $aMyfilelist[$i], @DocumentsCommonDir, $FC_OVERWRITE) Next You need to look at a for / next loop to do what you want This examples assumes you are in the same dir as the files and the destination is just an example If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
l3ill Posted January 19, 2014 Share Posted January 19, 2014 (edited) There is also a different way to get your files into an array. _FileListToArray Here is a working sample: (basically the example from the Help File changed to CopyFile's) #include <File.au3> #include <Array.au3> #include <MsgBoxConstants.au3> $destDir = @ScriptDir & "\DestFolder\" Example() Func Example() ; List all the files and folders in the desktop directory using the default parameters. Local $aFileList = _FileListToArray(@DesktopDir, "*", 1) If @error = 1 Then MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.") Exit EndIf If @error = 4 Then MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.") Exit EndIf ;========================================================== For $i = 1 To $aFileList[0] ;~ ConsoleWrite("$aFileList[$i] = " & $aFileList[$i] & @CRLF) FileCopy(@DesktopDir & "\" & $aFileList[$i], $destDir, 9) ;~ ConsoleWrite("@DesktopDir & $aFileList[$i] = " & @DesktopDir & $aFileList[$i] & @CRLF) Next ;========================================================== ;~ _ArrayDisplay($aFileList, "$aFileList") EndFunc ;==>Example Depending on the size of your files you might want to add a MsgBox tp tell you when the copy process is finished. Bill Edited January 19, 2014 by l3ill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
CiVQ Posted January 19, 2014 Share Posted January 19, 2014 (edited) Hello. First _FileListToArrayRec all files with $iReturn = 1 (files only). Store relative path is default in _FileListToArrayRec, so don't bother with that Then use the paths in a For loop: #include <File.au3> Local $szSourceDir = "C:\SourceDir\" Local $szDestDir = "C:\DestDir\" Local $aFiles = _FileListToArrayRec($szSourceDir, "*", 1, 1) For $i = 1 To $aFiles[0] FileCopy($szSourceDir&$aFiles[$i], $szDestDir&$aFiles[0], $FC_CREATEPATH) Next Of course, you will have to make some error checking (file listing, file exists, overwriting, etc.), which is lacked in my example. BR. CiV. Edited January 19, 2014 by CiVQ I know that my code is ugly. But it works. Mostly. 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