Jump to content
mrmacro

understanding usage of DirCopy and FileCopy

Recommended Posts

mrmacro

hi

I have made backup script that works but just want some clarification on the usage of Dircopy and FileCopy some parts I only want one file copied and other parts I want the whole directory copied

I looked in the help file but I just need someone to explain if I use the full path or just the path to the directory

here is the code for  the part I want clarified

;Scripts Directory (DirCopy) Restore
$source3 = "E:\Scripts"
$dest3 = "C:\Users\" & @UserName & "\Documents\Scripts"
If Not FileExists($dest3) Then
    DirCreate($dest3)
    DirCopy($source3, $dest3, $FC_OVERWRITE)
Else
    DirCopy($source3, $dest3, $FC_OVERWRITE)
EndIf

;KeePass File (FileCopy) Restore
$dest4 = "C:\Users\" & @UserName & "\Documents\KeePass"
$File4s = "E:\KeePass\NewDatabase.kdbx"
$File4d = "C:\Users\" & @UserName & "\Documents\KeePass\NewDatabase.kdbx"
$source4 = "E:\KeePass\NewDatabase.kdbx"
If Not FileExists($File4d) Then
    DirCreate($dest4)
    FileCopy($File4s, $File4d, $FC_OVERWRITE)
Else
    FileCopy($File4s, $File4d, $FC_OVERWRITE)
EndIf

with the DirCopy I can see I need just the directory for all the files there to be copied in to the new directory but I am unsure when using a File copy do I need to include the full file path and file name or just the directory?

 

Share this post


Link to post
Share on other sites
jo0oker

try this one i test it and its working

#include <file.au3>

;Scripts Directory (DirCopy) Restore
$source3 = "E:\Scripts"
$dest3 = (@UserProfileDir & "\Documents\Scripts")
If Not FileExists($dest3) Then
    DirCreate($dest3)
    DirCopy($source3, $dest3, $FC_OVERWRITE)
Else
    DirCopy($source3, $dest3, $FC_OVERWRITE)
EndIf

;KeePass File (FileCopy) Restore
$dest4 = (@UserProfileDir & "\Documents\KeePass")
$File4s = "E:\KeePass\NewDatabase.kdbx"
$File4d = (@UserProfileDir & "\Documents\KeePass\NewDatabase.kdbx")
$source4 = "E:\KeePass\NewDatabase.kdbx"
If Not FileExists($File4d) Then
    DirCreate($dest4)
    FileCopy($File4s, $File4d, $FC_OVERWRITE)
Else
    FileCopy($File4s, $File4d, $FC_OVERWRITE)
EndIf

 

Share this post


Link to post
Share on other sites
mrmacro

hi jo0oker 

it wasn't that its not working ,although I can see why you would think so because I only included an except of the full script and this is why you added in  

the #include <file.au3> , I also see that you have used a slight variation  of to get to the directory. :) thanks for that too

(@UserProfileDir & "\Documents\KeePass\NewDatabase.kdbx")

what I need info on is I am unsure when using a Filecopy do I need to include the full file path  

"C:\Users\" & @UserName & "\Documents\KeePass\NewDatabase.kdbx"

or as you have modified  

(@UserProfileDir & "\Documents\KeePass\NewDatabase.kdbx")

and file name or just  

"C:\Users\" & @UserName & "\Documents\KeePass"

?

Share this post


Link to post
Share on other sites
232showtime
17 hours ago, mrmacro said:

what I need info on is I am unsure when using a Filecopy do I need to include the full file path

Yes you need to include the full path for FileCopy. there are two different ways on including the full path.

Example:

$FPath = "C:\Users\user\Desktop"
$File = "New Text Document.txt"
If FileExists($FPath & "\" & $File) Then
    MsgBox(0, "", "File Found")
Else
    MsgBox(0, "", "File not Found")
EndIf


If FileExists(@DesktopDir & "\" & $File) Then
    MsgBox(0, "", "File Found")
Else
    MsgBox(0, "", "File not Found")
EndIf

 

 

  • Like 1

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
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

×