dumou8343 Posted March 10, 2014 Share Posted March 10, 2014 Hey everyone, I've been recently tasked to write some scripts with autoit, for now I'm loving it and this forum is great! but there is something I was not able to find. I'm copying some files from a Server to a PC and I need to log each file in a txt when they copy successfully. Here is a section of the code I have right now. Func Copie($Server1) $SourceInitial = $Server1 & "somepath" & @USERNAME & "somepath" $DestFinal = $Server1 & $Destination If FileExists($Server1&"somepath" & @Username & "somepath\Log.txt") Then WriteLog("Looks Good", $Server1) _FileCopy($Source, $DestFinal, 128) Else WriteLog("Copie Initial", $Server1) CopieInitial($SourceInitial) EndIf EndFunc Func _FileCopy($pFrom, $pTo, $fFlags = 0) Local $FOF_NOCONFIRMMKDIR = 512 Local $FOF_NOCONFIRMATION = 16 Local $FOF_FILESONLY = 128 If Not FileExists($pTo) Then DirCreate($pTo) $winShell = ObjCreate("shell.application") $winShell.namespace($pTo).CopyHere($pFrom, BitOR($FOF_NOCONFIRMMKDIR,$FOF_NOCONFIRMATION,$FOF_FILESONLY)) EndFunc Now all of this works great, but then in the filecopy I want tried to add a loop that sees each file one by one, gets the name and enter's it in my log file. I can't seem to get this to work. Thanks for the help! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 10, 2014 Moderators Share Posted March 10, 2014 dumou8343,Are you also Autonoobit? Multiple accounts are forbidden here - if the accounts are indeed both yours, which one do you want to keep? 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...
dumou8343 Posted March 11, 2014 Author Share Posted March 11, 2014 I might be, I don't remember if I made an account or not and with witch email, I would very much like to keep this account if both are mine. Sorry Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 11, 2014 Moderators Share Posted March 11, 2014 dumou8343,I have disabled the Autonoobit account - let us see if anyone complains. As to your problem I suggest you use a different approach to the copying. Use _FileListToArray to get a list of all the files in the source folder and then loop through the array using FileCopy to copy them to the destination folder. That way you can easily get the filenames as you you copy the files. 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...
dumou8343 Posted March 12, 2014 Author Share Posted March 12, 2014 So I've been trying this new approach all morning and can't figure out how to loop in the _filelisttoarray Here is what I got $aFirst = _FileListToArray("C:\source") $s = "" _Run($aFirst) Func _Run($a) For $i = 1 To UBound($a) - 1 $s = $s & $a[$i] & @CRLF $files = _FileListToArray($a[$i]) _FileCopy($files, "C\test\") If Not @error Then _Run($files) Next EndFunc MsgBox(0,"",$s) _FileCopy($s, "C\test\") 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 I can see the files in the message box, but can't seem to copy them Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 12, 2014 Moderators Share Posted March 12, 2014 (edited) dumou8343,You are overcomplicating the whole thing - just let AutoIt do the work for you: #include <File.au3> $sSource = "C:\source\" $sDest = "C\test\" ; Get an array of the files in the source folder $aFileList = _FileListToArray($sSource, "*.*", 1) ; Loop through them - the count is in the [0] element For $i = 1 To $aFileList[0] ; And copy them FileCopy($sSource & $aFileList[$i], $sDest & $aFileList[$i]) ; You can add the files copies to a list here NextM23 Edited March 13, 2014 by Melba23 Amended code 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...
dumou8343 Posted March 13, 2014 Author Share Posted March 13, 2014 Hello Melba23, I'm sorry to be such a drag, but I was wondering what build you were using and witch includes you were using. Your code does not work for me. I get the error: "C:AutoitMelbatest.au3" (17) : ==> Unknown function name.: $aFileList = FileListToArray($sSource) $aFileList = ^ ERROR Then I found the #include<FileListToArray3.au3> and got that working, but nothing is copying, did I forget an include? I currently have these include #include <Array.au3> #include<FileListToArray3.au3> #include <FileConstants.au3> Thanks for your patience! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 13, 2014 Moderators Share Posted March 13, 2014 (edited) dumou8343,Oops! Missed an underscore - not a good day yesterday for various reasons. It should read "_FileListToArray" and you need #include<File.au3>. M23Edit: I have amended the code I posted yesterday. Edited March 13, 2014 by Melba23 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...
dumou8343 Posted March 13, 2014 Author Share Posted March 13, 2014 Hey Melba23, Now I see why it was not working! You also forgot the : for c:test ! Its working perfectly! Thanks a million! I hope you have a better day today then yesterday! and Cheer up, tomorrow is friday Thanks again! I love this community! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 13, 2014 Moderators Share Posted March 13, 2014 dumou8343,Sorry again for the errors - glad we got there in the end. 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...
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