Jump to content

Filecopy and structure probably not understund


Recommended Posts

Hi guys  i read  a help (this time :)) and  in file copy i see exist a flag 

FC_CREATEPATH (8) = Create destination directory structure if it doesn't exist (See Remarks).

 

but in my  windows xp happen this , copy  a folder source   and destination but  without blank folder and folder full of  file  not create structure but copy only file

some one can help me ?? this is  a script

#include <File.au3>
#include <Date.au3>


_FileCopyLOG("C:\Documents and Settings\Admin\Desktop\ba", "C:\Documents and Settings\Admin\Desktop\ma", "C:\Documents and Settings\Admin\Desktop\back.txt", "", "",   $FC_CREATEPATH )

Func _FileCopyLOG($Path, $DestPath, $LogPath, $LogOKO, $FlagFTA = 0, $Flag = 1)
    If $FlagFTA = Default Then $FlagFTA = 0
    If $Flag = Default Then $Flag = 1
    If $LogOKO = Default Then $LogOKO = 0

    Local $aFileList = _FileListToArray($Path, "*.*", $FlagFTA)
    _ArrayDisplay($aFileList)
    If @error = 1 Then
        ;MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.")
        Return 1
    ElseIf @error = 4 Then
        ; MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
        Return 4
    ElseIf @error = 2 Then
        ; MsgBox($MB_SYSTEMMODAL, "", "Invalid Filter")
        Return 2
    ElseIf @error = 3 Then
        ; MsgBox($MB_SYSTEMMODAL, "", "Invalid Flag")
        Return 3
    Else
        Local $ReturnCopy
        For $i = 1 To UBound($aFileList) - 1
            $ReturnCopy = FileCopy($Path & "\" & $aFileList[$i], $DestPath, $Flag)
        ;   $ReturnCopy = DirCopy($Path & "\" & $aFileList[$i], $DestPath, $Flag)
            If $LogPath <> "" Then
                Local $sTime = _DateTimeFormat(_NowCalc(), 0)
                Local $rep1 = StringReplace($sTime, " ", "-")
                Local $rep2 = StringReplace($rep1, "/", "-")
                Local $rep3 = StringReplace($rep2, ":", "-")
                $rep3 = StringReplace($rep2, ":", "-")
                Local $sLLogPath = StringTrimRight($LogPath, 4)
                If $ReturnCopy = 1 And $LogOKO = 0 Then
                    _True_write_File($sLLogPath & "_" & $rep3 & ".log", $Path & "\" & $aFileList[$i] & "  ----------->  COPIATO")
                ElseIf $ReturnCopy = 0 And $LogOKO = 1 Then
                    _True_write_File($LogPath, $Path & "\" & $aFileList[$i] & "  ----------->  NON COPIATO")
                ElseIf $ReturnCopy = 0 And $LogOKO = 0 Then
                    _True_write_File($LogPath, $Path & "\" & $aFileList[$i] & "  ----------->  NON COPIATO")
                EndIf
            EndIf
        Next
        Return 5
    EndIf
EndFunc   ;==>_FileCopyLOG

; #INDEX# ========================================================================
; Title .........: GUI_Configure.au3
; AutoIt Version : 3.3.14.2++
; Language ......: Italian
; Description ...: A collection of Function for Logic of Gest
; Author ........: Faustf
; What do you do.: Write data in File
; Version .......: 0.0.1 BETA - Work in progress 15/03/2016
; Syntax ........:
; ================================================================================

Func _True_write_File($sFilePath, $sDataWrite, $iReturn = 0)
    If $iReturn = Default Then $iReturn = 0

    $File = FileOpen($sFilePath, 1)
    If $iReturn = 0 Then
        FileWrite($File, $sDataWrite & @CRLF)
    Else
        FileWrite($File, $sDataWrite)
    EndIf
    FileClose($File)

EndFunc   ;==>_True_write_File

 

Link to comment
Share on other sites

I'm not sure what your actual problem is, but this will never work the way you're expecting.

Local $aFileList = _FileListToArray($Path, "*.*", $FlagFTA)
    _ArrayDisplay($aFileList)
    If @error = 1 Then

Your use of _ArrayDisplay resets the @error so the entire IF structure after it will never work the way you want it to.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

i  try to semplify a script with this  3  row  and  have the same problem not create path  in destination but copy all file (included file located in subfolder) in main folder destination  o_O

#include <File.au3>
#include <Date.au3>

;Local $aFileList = _FileListToArray("C:\Users\SviluppoGest\Desktop\ba", "*.*", 0)
Local $aFileList = _FileListToArray("C:\Users\SviluppoGest\Desktop\ba")


For $i =0 To UBound ($aFileList) -1

FileCopy("C:\Users\SviluppoGest\Desktop\ba\"&$aFileList[$i], "C:\Users\SviluppoGest\Desktop\ma", $FC_OVERWRITE  + $FC_CREATEPATH )

Next

i think at this point is bug of autoit

 

Link to comment
Share on other sites

What main folder is it copying the files to, the ma folder?

Because if so, that's where you told it to copy them to. There's no path information in the array, so where do you expect them to go to?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

faustf,

Quote

i think at this point is bug of

faustf - as this works perfectly for me:

#include <File.au3>

Local $aFileList = _FileListToArray("M:\Program\Au3 Scripts\faustf", "*", $FLTA_FILES, True)

For $i = 0 To UBound($aFileList) - 1

    FileCopy($aFileList[$i], "M:\Program\Au3 Scripts\test", $FC_OVERWRITE + $FC_CREATEPATH)
    
Next

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

 

Link to comment
Share on other sites

  • Moderators

faustf,

FileCopy does what it says - moves files. If you want to create subfolders as well then you are in a whole new game - look at DirCopy in the Help file.

M23

P.S. I seem to recall the point of you not reading the Help file before posting being discussed recently? Please do take the advice to heart.

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

 

Link to comment
Share on other sites

3 minutes ago, faustf said:

recreate thesame structure inside

There's NO structure in that that can be created, what folder are you expecting it to create that it isn't?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

@Melba23 i take  a  care  the advice to heart., and  i read  file  help  therfore  if  in help  write:  

  $FC_CREATEPATH (8) = Create destination directory structure if it doesn't exist (See Remarks).

i think work  correct  , but  i take note   the  help file  have  some error because  the  flag  $FC_CREATEPATH(8)  , not  Create destination directory structure


 
Link to comment
Share on other sites

  • Moderators

faustf,

That phrase means that the command will create the necessary directory structure in the copied file path if it does not already exist - try this (you may have to adjust the paths):

#include <File.au3>

FileCopy(@ScriptFullPath, @ScriptDir & "\test\", $FC_CREATEPATH) ; make sure new folder does not already exist!!

You will get a copy of the script file in the new folder - note the trailing "\" so AutoIt knows you want to create a folder.

It does not mean that it creates all the subsidiary files within the structure - for that you need DirCopy as I have already told you.

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

 

Link to comment
Share on other sites

so so so i think   file  copy and  dir  copy , must have, rewrite , probably  when  born a concept is correct but now  is bad very bad , obviously
 if  you must copy one  simple  file  and  go  you can use  it  , but if you must rely on it  is very bad!!!!!!!  , i think instead change _arraydisplay   and  create another instruction _arraydisplay debug (or similar  now not remember perfectly name  )I would have improved , or add , a new powerfull instruction , becuase  if  you immagine in robocopy you can do  in one simple instruction  copy  structure  file  and logging  it 

robocopy.exe ' & $from & ' ' & $to & ' ' & $options & ' ' & $logpath,

and  in autoit  you must  go crazy  with filecopy and dircopy  and  _FileListToArray   and  after for  write  log  restart the  hell  open file  write it  close it , programming speed is  important today , therfore Unfortunately i use a simply cmd  command .

thankz again for  help 

 

P.S: i insert a \  in script  but  have  the same effect 

 

Link to comment
Share on other sites

  • Moderators

faustf,

Quote

 in autoit  you must  go crazy  with filecopy and dircopy 

Not at all! DirCopy will automatically copy the directory structure and the files within it - no need to use FileCopy or FileReadToArray or anything else - just the one simple command. How about trying it before complaining?

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

 

Link to comment
Share on other sites

therfore  if  i  use this  script  must  work   ??? 

#include <File.au3>
#include <Date.au3>

;Local $aFileList = _FileListToArray("C:\Users\SviluppoGest\Desktop\ba", "*.*", 0)
Local $aFileList = _FileListToArray("C:\Users\SviluppoGest\Desktop\ba")


;For $i =0 To UBound ($aFileList) -1

;FileCopy("C:\Users\SviluppoGest\Desktop\ba\"&$aFileList[$i], "C:\Users\SviluppoGest\Desktop\ma\", $FC_OVERWRITE  + $FC_CREATEPATH )
DirCopy ("C:\Users\SviluppoGest\Desktop\ba\", "C:\Users\SviluppoGest\Desktop\ma", $FC_OVERWRITE  )

;Next

 

Edited by faustf
Link to comment
Share on other sites

  • Moderators

faustf,

Quote

ok  Dircopy  is  good 

Delighted to hear it.

Quote

i want also a log  file

You could run _FileListToArrayRec on the 2 structures and see if they match - then use one of the arrays to write to the log file using _FileWriteFromArray (but take care not to overwrite the earlier entries).

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

 

Link to comment
Share on other sites

at  end  i preferred work with  Robocopy , because create a perfect style log , and  is very simply

this is a  code i created  , is not perfect  but perfectible , thankz  at all 

#include <File.au3>
#include <Date.au3>


;_FileCopyLOG("C:\Users\SviluppoGest\Desktop\ba", "C:\Users\SviluppoGest\Desktop\ma", "C:\Users\SviluppoGest\Desktop\back.txt", "", "",1,1)


; #FUNCTION# ====================================================================================================================
; Name ..........: _FileCopyLOG
; Description ...: File copy and log with Robocopy
; Syntax ........: _FileCopyLOG($Path, $DestPath, $LogPath, $FlagFTA = 0, $Flag = 0, $cmdflag = 0, $visible = 0)
; Parameters ....: $Path        - dirctory you wish copy
;                  $DestPath    - base directory where output goes
;                  $LogPath     - log path if you want log , if you dont want simply ""
;                  $FlagFTA     - flag option of _FileListToArray (see help for details)
;                  $Flag        - flag option Robocopy  (see help robocopy for details,cmd --> robocopy /? )
;                  $cmdflag     - flag option for command Run (see help for Eun cmmand, usally c  or k)
;                  $visible     - flag for see cmd (active or disactive @SW_HIDE)
; Return values .:
; Author ........: Faustf
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: decomment 5° line and insert your path
; ===============================================================================================================================

Func _FileCopyLOG($Path, $DestPath, $LogPath, $FlagFTA = 0, $Flag = 0, $cmdflag = 0, $visible = 0)

    If $FlagFTA = Default Then $FlagFTA = 0
    If $Flag = 0 Then $Flag = "/E"
    If $cmdflag = 0 Then
        $cmdflag = "c"
    Else
        $cmdflag = "k"
    EndIf
    If $visible = 0 Then
        $visible = ""
    Else
        $visible =  @SW_HIDE
    EndIf
    Local $aFileList = _FileListToArray($Path, "*.*", $FlagFTA)
    ;_ArrayDisplay($aFileList)
    If @error = 1 Then
        ;MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.")
        Return 1
    ElseIf @error = 4 Then
        ; MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
        Return 4
    ElseIf @error = 2 Then
        ; MsgBox($MB_SYSTEMMODAL, "", "Invalid Filter")
        Return 2
    ElseIf @error = 3 Then
        ; MsgBox($MB_SYSTEMMODAL, "", "Invalid Flag")
        Return 3
    Else
        If @OSVersion = "WIN_XP" Then
            Local $sLRoboFileDir = FileGetShortName(@ProgramFilesDir & '\Windows Resource Kits\Tools\robocopy.exe ')
            Local $sLFromShort = FileGetShortName($Path)
            Local $sLToShort = FileGetShortName($DestPath)
            Local $sLOptShort = FileGetShortName($Flag)
            Local $sLOgShort = FileGetShortName($LogPath)

            If FileExists($sLRoboFileDir) Then
                If $LogPath = "" Then
                    Run(@ComSpec & ' /k ' & $sLRoboFileDir & ' ' & $sLFromShort & ' ' & $sLToShort & ' ' & $sLOptShort ,'', $visible))
                Else
                    Run(@ComSpec & ' /k ' & $sLRoboFileDir & ' ' & $sLFromShort & ' ' & $sLToShort & ' ' & $sLOptShort & '  /LOG:' & $sLOgShort,'', $visible)
                EndIf
            Else
                MsgBox(48, 'Info', 'You must install robocopy')
                ShellExecute("https://www.microsoft.com/en-us/download/details.aspx?id=17657")
            EndIf
        Else
            If FileExists(@SystemDir & '\robocopy.exe') Then
                If $LogPath = "" Then
                    Run(@ComSpec & ' /'&$cmdflag&' ' & @SystemDir & '\robocopy.exe ' & $Path & ' ' & $DestPath & ' ' & $Flag,'', $visible)
                Else
                    Run(@ComSpec & ' /'&$cmdflag&' ' & @SystemDir & '\robocopy.exe ' & $Path & ' ' & $DestPath & ' ' & $Flag & '  /LOG:' & $LogPath, '', $visible)
                EndIf
            Else
                MsgBox(48, 'Info', 'You must install robocopy')
                ShellExecute("https://www.microsoft.com/en-us/download/details.aspx?id=17657")
            EndIf
        EndIf
        Return 5
    EndIf
EndFunc   ;==>_FileCopyLOG


; #INDEX# ========================================================================
; Title .........: GUI_Configure.au3
; AutoIt Version : 3.3.14.2++
; Language ......: Italian
; Description ...: A collection of Function for Logic of Gest
; Author ........: Faustf
; What do you do.: Write data in File
; Version .......: 0.0.1 BETA - Work in progress 15/03/2016
; Syntax ........:
; ================================================================================

Func _True_write_File($sFilePath, $sDataWrite, $iReturn = 0)
    If $iReturn = Default Then $iReturn = 0

    $File = FileOpen($sFilePath, 1)
    If $iReturn = 0 Then
        FileWrite($File, $sDataWrite & @CRLF)
    Else
        FileWrite($File, $sDataWrite)
    EndIf
    FileClose($File)

EndFunc   ;==>_True_write_File

 

Link to comment
Share on other sites

  • Moderators
7 hours ago, faustf said:

so so so i think   file  copy and  dir  copy , must have, rewrite , probably  when  born a concept is correct but now  is bad very bad , obviously
 if  you must copy one  simple  file  and  go  you can use  it  , but if you must rely on it  is very bad!!!!!!!

So, the functions should be re-written because you (and only you) are not intelligent enough to understand them? Really getting tired of you complaining about and blaming the language because you're not able to grasp the simplest of concepts...

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...