Jump to content

Copy some files in Folder/sub and create directory structure


Recommended Posts

Hello;

I want to copy all files *.dat from a folder to an other to backup some files.

I've used the function FileCopy but this command don't create every subfolder where some file *.dat are in.

#include <Date.au3>
#include <Array.au3>
#include <File.au3>
#include <_FileListToArrayEx.au3>
#include <RecFileListToArray.au3>

$Dossier_racine = "Z:\test_Backup"
$Dossier_a_sauvegarder = "C:\WINDOWS\Temp"
$type_fichier_a_sauvegarder = "*.dat"

$numsemaine_00 = _WeekNumberISO()

$Dossier_backup_semaine_00 = $Dossier_racine & "\" & $numsemaine_00
 
dircreate($Dossier_backup_semaine_00)
FileCopy($Dossier_a_sauvegarder & "\" & $type_fichier_a_sauvegarder, $Dossier_backup_semaine_00, 9) ; Flag = 1 + 8 (overwrite + create target directory structure)

The command FileCopy, copy only the files into C:\WINDOWS\Temp but not the files into "C:\WINDOWS\Temp\crt" and dont create this subfolder into my backup folder.

How can I do that ?

Thanks.

Link to comment
Share on other sites

  • Moderators

cortx,

Use my _RecFileListToArray UDF (look in my sig) to list all the *.dat files in the root folder and its subfolders and then loop through the returned array using FileCopy to create the new files. :)

Give it a go yourself - you know where we are if you run into difficulties. ;)

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

cortx,

I've already used it for the rest of my script

Then you should have no problem at all! :D

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

func Sauvegarde_semaine_00()
dircreate($Dossier_backup_semaine_00)
$FileListbackup = _RecFileListToArray ($Dossier_a_sauvegarder, $type_fichier_a_sauvegarder, 1, 1, 1)

If not @Error Then
For $i = 1 to $FileListbackup[0]
FileCopy($Dossier_a_sauvegarder & "" & $FileListbackup[$i], $Dossier_backup_semaine_00 & "" & $FileListbackup[$i], 9)
Next
EndIf
EndFunc

Luke, I'm your Father ;D

Yes it's so weak for you but for me that make my day.

Edited by cortx
Link to comment
Share on other sites

  • Moderators

cortx,

This is what I had ready if needed:

#include <RecFileListToArray.au3>

$sRoot = "Your_Old_Path"
$sDest = "Your_New_Path"

$aList = _RecFileListToArray($sRoot, "*.dat", 1, 1)

For $i = 1 To $aList[0]
    FileCopy($sRoot & $aList[$i], $sDest & $aList[$i], 8)
Next

Looks pretty close! :D

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

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...