Jump to content

Recommended Posts

Posted

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!

  • Moderators
Posted

dumou8343,

Are you also Autonoobit? Multiple accounts are forbidden here - if the accounts are indeed both yours, which one do you want to keep? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

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 :(

  • Moderators
Posted

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

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

  • Moderators
Posted (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
Next
M23 Edited by Melba23
Amended code

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

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!

  • Moderators
Posted (edited)

dumou8343,

Oops! Missed an underscore - not a good day yesterday for various reasons. :>

It should read "_FileListToArray" and you need #include<File.au3>. :)

M23

Edit: I have amended the code I posted yesterday. ;)

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

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 :P

Thanks again! I love this community!

  • Moderators
Posted

dumou8343,

Sorry again for the errors - glad we got there in the end. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...