Guest Bilou_Gateux Posted August 1, 2005 Share Posted August 1, 2005 (edited) Could some one post an AutoIT script to call the function from within a batch file (bat or cmd). autoit3.exe filecopy.au3 source destination Example source=D:\AI\SOURCE\I386\ is the Command Line Parameter 1 destination=C:\I386\ is Command Line Parameter 2 values are passed to the function _CopyDirWithProgress("D:\AI\SOURCE\I386\", "C:\I386\") Edited August 1, 2005 by Bilou_Gateux Link to comment Share on other sites More sharing options...
blindwig Posted August 1, 2005 Share Posted August 1, 2005 Could some one post an AutoIT script to call the function from within a batch file (bat or cmd).autoit3.exe filecopy.au3 source destinationExamplesource=D:\AI\SOURCE\I386\ is the Command Line Parameter 1destination=C:\I386\ is Command Line Parameter 2values are passed to the function _CopyDirWithProgress("D:\AI\SOURCE\I386\", "C:\I386\")<{POST_SNAPBACK}>Why all that work? Why not just use XCOPY? That will do recursive folders and even has an option to do hidden files/folders as well. My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
ezzetabi Posted August 2, 2005 Author Share Posted August 2, 2005 ...I hate this kind of answers... Why not use XXCopy? It permit also copying NTFS rights!So? What? He asked something different!just use $cmdline[]if $cmdline[0] > 1 Then _CopyDirWithProgress($cmdline[1], $cmdline[2]) ;Some error checking here endif Link to comment Share on other sites More sharing options...
blindwig Posted August 2, 2005 Share Posted August 2, 2005 ...I hate this kind of answers... Why not use XXCopy? It permit also copying NTFS rights!So? What? He asked something different!just use $cmdline[]if $cmdline[0] > 1 Then _CopyDirWithProgress($cmdline[1], $cmdline[2]) ;Some error checking here endif<{POST_SNAPBACK}>He said he wanted a program to recursively copy files, and that he wanted to be able to call it on the command line. My question is why write your own program to do that when one already exists and is already available on every MS machine? It would reduce his development/debugging time as well as reduce the overall size of whatever he's distributing. My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
Proph Posted August 2, 2005 Share Posted August 2, 2005 He said he wanted a program to recursively copy files, and that he wanted to be able to call it on the command line. My question is why write your own program to do that when one already exists and is already available on every MS machine? It would reduce his development/debugging time as well as reduce the overall size of whatever he's distributing.<{POST_SNAPBACK}>Simple... I want to have this progressbar. It looks very professional. I don't like having a dos window popping up... and I don't want to just hide the dos window and not show progress. I allready know how to use xcopy... and that is the idea... I want to be able to basically do what xcopy does... but with ezzetabi's progressbar. Link to comment Share on other sites More sharing options...
Guest Bilou_Gateux Posted August 4, 2005 Share Posted August 4, 2005 @Proph,I can't say better than your answer.@blindwigHaving a gui is usefull when installing Unattended Windows.From winnt.sif DetachedProgram or $OEM$\cmdlines.txt, you can launch some commands with parameters.you probably never heard of this... each user have different needs.@ezzetabii will try looking in the tutorials for more details about this command and add this to code.Thanks. Link to comment Share on other sites More sharing options...
Proph Posted August 6, 2005 Share Posted August 6, 2005 @Bilou_Gateux As you requested... Here is what you need to call the progressbar from any script. Just call the exe with 2 parameters... Parameter 1 is the source. Parameter 2 is the destination. So if you named it progressbar.exe and wanted to copy "c:\source" to "d:\destination" you would put it in your batch file or script like this... progressbar.exe "c:\source" "d:\destination" expandcollapse popupIf $cmdline[0] = 2 Then $sOriginalDir = $cmdline[1] $sDestDir = $cmdline[2] Else MsgBox(0,'Invalid # of parameters!',$cmdline[0]&' is an Invalid number of parameters.') Exit EndIf Func _CopyDirWithProgress($sOriginalDir, $sDestDir) ;$sOriginalDir and $sDestDir are quite selfexplanatory... ;This func returns: ; -1 in case of critical error, bad original or destination dir ; 0 if everything went all right ; >0 is the number of file not copied and it makes a log file ; if in the log appear as error message '0 file copied' it is a bug of some windows' copy command that does not redirect output... If StringRight($sOriginalDir, 1) <> '\' Then $sOriginalDir = $sOriginalDir & '\' If StringRight($sDestDir, 1) <> '\' Then $sDestDir = $sDestDir & '\' If $sOriginalDir = $sDestDir Then Return -1 ProgressOn('Copying...', 'Making list of files...' & @LF & @LF, '', -1, -1, 18) Local $aFileList = _FileSearch($sOriginalDir) If $aFileList[0] = 0 Then ProgressOff() SetError(1) Return -1 EndIf If FileExists($sDestDir) Then If Not StringInStr(FileGetAttrib($sDestDir), 'd') Then ProgressOff() SetError(2) Return -1 EndIf Else DirCreate($sDestDir) If Not FileExists($sDestDir) Then ProgressOff() SetError(2) Return -1 EndIf EndIf Local $iDirSize, $iCopiedSize = 0, $fProgress = 0 Local $c, $FileName, $iOutPut = 0, $sLost = '', $sError Local $Sl = StringLen($sOriginalDir) _Quick_Sort($aFileList, 1, $aFileList[0]) $iDirSize = Int(DirGetSize($sOriginalDir) / 1024) ProgressSet(Int($fProgress * 100), $aFileList[$c], 'Coping file:') For $c = 1 To $aFileList[0] $FileName = StringTrimLeft($aFileList[$c], $Sl) ProgressSet(Int($fProgress * 100), $aFileList[$c] & ' -> '& $sDestDir & $FileName & @LF & 'Total KiB: ' & $iDirSize & @LF & 'Done KiB: ' & $iCopiedSize, 'Coping file: ' & Round($fProgress * 100, 2) & ' % ' & $c & '/' &$aFileList[0]) If StringInStr(FileGetAttrib($aFileList[$c]), 'd') Then DirCreate($sDestDir & $FileName) Else If Not FileCopy($aFileList[$c], $sDestDir & $FileName, 1) Then If Not FileCopy($aFileList[$c], $sDestDir & $FileName, 1) Then;Tries a second time If RunWait(@ComSpec & ' /c copy /y "' & $aFileList[$c] & '" "' & $sDestDir & $FileName & '">' & @TempDir & '\o.tmp', '', @SW_HIDE)=1 Then;and a third time, but this time it takes the error message $sError = FileReadLine(@TempDir & '\o.tmp',1) $iOutPut = $iOutPut + 1 $sLost = $sLost & $aFileList[$c] & ' ' & $sError & @CRLF EndIf FileDelete(@TempDir & '\o.tmp') EndIf EndIf FileSetAttrib($sDestDir & $FileName, "+A-RSH");<- Comment this line if you do not want attribs reset. $iCopiedSize = $iCopiedSize + Int(FileGetSize($aFileList[$c]) / 1024) $fProgress = $iCopiedSize / $iDirSize EndIf Next ProgressOff() If $sLost <> '' Then;tries to write the log somewhere. If FileWrite($sDestDir & 'notcopied.txt',$sLost) = 0 Then If FileWrite($sOriginalDir & 'notcopied.txt',$sLost) = 0 Then FileWrite(@WorkingDir & '\notcopied.txt',$sLost) EndIf EndIf EndIf Return $iOutPut EndFunc ;==>_CopyDirWithProgress Func _FileSearch($sIstr, $bSF = 1) ; $bSF = 1 means looking in subfolders ; $sSF = 0 means looking only in the current folder. ; An array is returned with the full path of all files found. The pos [0] keeps the number of elements. Local $sIstr, $bSF, $sCriteria, $sBuffer, $iH, $iH2, $sCS, $sCF, $sCF2, $sCP, $sFP, $sOutPut = '', $aNull[1] $sCP = StringLeft($sIstr, StringInStr($sIstr, '\', 0, -1)) If $sCP = '' Then $sCP = @WorkingDir & '\' $sCriteria = StringTrimLeft($sIstr, StringInStr($sIstr, '\', 0, -1)) If $sCriteria = '' Then $sCriteria = '*.*' ;To begin we seek in the starting path. $sCS = FileFindFirstFile($sCP & $sCriteria) If $sCS <> - 1 Then Do $sCF = FileFindNextFile($sCS) If @error Then FileClose($sCS) ExitLoop EndIf If $sCF = '.' Or $sCF = '..' Then ContinueLoop $sOutPut = $sOutPut & $sCP & $sCF & @LF Until 0 EndIf ;And after, if needed, in the rest of the folders. If $bSF = 1 Then $sBuffer = @CR & $sCP & '*' & @LF;The buffer is set for keeping the given path plus a *. Do $sCS = StringTrimLeft(StringLeft($sBuffer, StringInStr($sBuffer, @LF, 0, 1) - 1), 1);current search. $sCP = StringLeft($sCS, StringInStr($sCS, '\', 0, -1));Current search path. $iH = FileFindFirstFile($sCS) If $iH <> - 1 Then Do $sCF = FileFindNextFile($iH) If @error Then FileClose($iH) ExitLoop EndIf If $sCF = '.' Or $sCF = '..' Then ContinueLoop If StringInStr(FileGetAttrib($sCP & $sCF), 'd') Then $sBuffer = @CR & $sCP & $sCF & '\*' & @LF & $sBuffer;Every folder found is added in the begin of buffer $sFP = $sCP & $sCF & '\'; for future searches $iH2 = FileFindFirstFile($sFP & $sCriteria); and checked with the criteria. If $iH2 <> - 1 Then Do $sCF2 = FileFindNextFile($iH2) If @error Then FileClose($iH2) ExitLoop EndIf If $sCF2 = '.' Or $sCF2 = '..' Then ContinueLoop $sOutPut = $sOutPut & $sFP & $sCF2 & @LF;Found items are put in the Output. Until 0 EndIf EndIf Until 0 EndIf $sBuffer = StringReplace($sBuffer, @CR & $sCS & @LF, '') Until $sBuffer = '' EndIf If $sOutPut = '' Then $aNull[0] = 0 Return $aNull Else Return StringSplit(StringTrimRight($sOutPut, 1), @LF) EndIf EndFunc ;==>_FileSearch Func _Quick_Sort(ByRef $SortArray, $First, $Last);Larry's code Dim $Low, $High Dim $Temp, $List_Separator $Low = $First $High = $Last $List_Separator = StringLen($SortArray[ ($First + $Last) / 2]) Do While (StringLen($SortArray[$Low]) < $List_Separator) $Low = $Low + 1 WEnd While (StringLen($SortArray[$High]) > $List_Separator) $High = $High - 1 WEnd If ($Low <= $High) Then $Temp = $SortArray[$Low] $SortArray[$Low] = $SortArray[$High] $SortArray[$High] = $Temp $Low = $Low + 1 $High = $High - 1 EndIf Until $Low > $High If ($First < $High) Then _Quick_Sort($SortArray, $First, $High) If ($Low < $Last) Then _Quick_Sort($SortArray, $Low, $Last) EndFunc ;==>_Quick_Sort _CopyDirWithProgress($sOriginalDir, $sDestDir) Enjoy! Link to comment Share on other sites More sharing options...
Amen Posted August 6, 2005 Share Posted August 6, 2005 Nice Work and Very usefull function that you've created! Plugged ThoughtsQBsick? check my Old staff (New Launchers to Work with Windows.Thnx to Autoit!)Game Development ToolsPortes (A Backgammon game)Ball (An Arkanoid Style game)Au3? SecretProgz - Reveals Commands that can be used on your system CleanOut - Uninstall leftovers Enable windows XP Autologon. Stop Windows Auto Sharing your hard drives (C$,D$,etc) D-Link - Create a dynamic link.Useful for server shortcuts Fun - How would your name sounds in Japanese,Russian or Reventian? Fix_srt - Shift a subtitle (.srt) some secs +/- Link to comment Share on other sites More sharing options...
ezzetabi Posted August 6, 2005 Author Share Posted August 6, 2005 Nice job Proph, but you should always put all func in the bottom or in the begin of the script. Putting Functions in the middle as you did is ugly (even if it works exactly at the same way...). In fact your program seems incomplete at the first look. I usually even put a EXIT just before the functions, in order to make clear that the main program is ended, if I need OnAutoItStart() I put it as first function. The program is more tidy that way... ;Main program Exit Func OnAutoItStart() ;Blah EndFunc ;Other funcs.... Link to comment Share on other sites More sharing options...
Proph Posted August 7, 2005 Share Posted August 7, 2005 Nice tip. I will do that in the future. Link to comment Share on other sites More sharing options...
lyledg Posted August 10, 2005 Share Posted August 10, 2005 Was just wondering, what would need to change in this script if I wanted to use GUICtrlCreateProgress? Cheers Link to comment Share on other sites More sharing options...
themax90 Posted August 11, 2005 Share Posted August 11, 2005 Yo I love this, it will help with installers, great work!!! Link to comment Share on other sites More sharing options...
slowhand63 Posted December 22, 2006 Share Posted December 22, 2006 If I use This script, I got this error: C:\autoit\copy.au3 (185) : ==> Can not redeclare a parameter inside a user function.: Local $sIstr, $bSF, $sCriteria, $sBuffer, $iH, $iH2, $sCS, $sCF, $sCF2, $sCP, $sFP, $sOutPut = '', $aNull[1] Local ^ ERROR +>AutoIT3.exe ended.rc:0 >Exit code: 0 Time: 11.474 and I´m a totally newbie in AutoIt regards slowhand63 Link to comment Share on other sites More sharing options...
hoppy Posted December 22, 2006 Share Posted December 22, 2006 same error here Can not redeclare a parameter inside a user functionany idea'sthanks Link to comment Share on other sites More sharing options...
Tom42 Posted February 5, 2007 Share Posted February 5, 2007 same error here Can not redeclare a parameter inside a user functionany idea'sthankssame here Link to comment Share on other sites More sharing options...
Charus Posted February 17, 2007 Share Posted February 17, 2007 hello. i need some help. pls anyone... i want to add this function in my code my code is: if FileExists("c:\test.txt") Then run("notepad", "c:\windows\", @SW_MAXIMIZE) Else DirCopy("\\kill-bill\Server\", "c:\", 1) EndIf Exit i want to copy files from server to my pc and i want to have a progress bor to check the status progress Link to comment Share on other sites More sharing options...
MHz Posted February 17, 2007 Share Posted February 17, 2007 i want to copy files from server to my pc and i want to have a progress bor to check the status progressTry the Com method as it will show the windows default copy dialog and works with file and directories.http://www.autoitscript.com/forum/index.ph...st&p=186168 Link to comment Share on other sites More sharing options...
Hello Me You Posted February 17, 2007 Share Posted February 17, 2007 thanks, nice script Random Link to comment Share on other sites More sharing options...
Charus Posted February 17, 2007 Share Posted February 17, 2007 thanks MHz but this script copy only 1 file... i want to copy all the folder with subfolders etc... Link to comment Share on other sites More sharing options...
MHz Posted February 18, 2007 Share Posted February 18, 2007 thanks MHz but this script copy only 1 file... i want to copy all the folder with subfolders etc...Copying the directory works for me. Try this _FileCopy(@WindowsDir & "\Resources\",@HomeDrive & '\') Func _FileCopy($fromFile,$tofile) Local $FOF_RESPOND_YES = 16 Local $FOF_SIMPLEPROGRESS = 256 $winShell = ObjCreate("shell.application") $winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES) EndFunc It copies the folder and subfolders with a progress dialog. 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