Jump to content

DirCopy not working.. HELP!


Go to solution Solved by DW1,

Recommended Posts

I am trying to copy folders from the C drive, place them in a folder and rename them to current year, date and day. However I am having issues with DirCopy not even working. Could anyone please assist? With in those folders are multiple files so from the Help file it looks like DirCopy is the only way to go. Once the folders are copied over they need to be changed to show the year, date and month.

Here is the code I have written:

DirCopy(@DesktopDir & "\Test", @DesktopDir & "\Test\Backup", 1)

I thought I would try to get this code working before I tried to rename the folders. Any help would be greatly appreciated!

 

Link to comment
Share on other sites

 

I am trying to copy folders from the C drive, place them in a folder and rename them to current year, date and day. However I am having issues with DirCopy not even working. Could anyone please assist? With in those folders are multiple files so from the Help file it looks like DirCopy is the only way to go. Once the folders are copied over they need to be changed to show the year, date and month.

Here is the code I have written:

DirCopy(@DesktopDir & "\Test", @DesktopDir & "\Test\Backup", 1)

I thought I would try to get this code working before I tried to rename the folders. Any help would be greatly appreciated!

 

Your code as it sits, works exactly as expected for me.  Win 7 x64 AutoIt 3.3.8.1

Link to comment
Share on other sites

Your code as it sits, works exactly as expected for me.  Win 7 x64 AutoIt 3.3.8.1

 

When I run this nothing happens.. I am running Win & x64 Autoit 3. Am i correct to assume that when i run this all of the folders and files within Test would copy over to TestBackup?

Link to comment
Share on other sites

When I run this nothing happens.. I am running Win & x64 Autoit 3. Am i correct to assume that when i run this all of the folders and files within Test would copy over to TestBackup?

Yes, that is correct, however, I may see the confusion.  When I tested, I tested only against files, not sub-directories.  I'm thinking that michaelslamet is correct that when using dircopy with a destination within the source directory, only files will be copied, not folders.

Does that explain the behavior you are seeing?

Link to comment
Share on other sites

 

If that's the case, does this work more how you expected?

DirCopy(@DesktopDir & "\Test", @TempDir & "\MyTempDir", 1)
DirMove(@TempDir & "\MyTempDir", @DesktopDir & "\Test\Backup", 1)

 

Ah! ok that worked! Could you explain as to why you had to create a TempDir the move the TempDir to Backup? But great thanks! Is there a way to rename those folders after it's copied to the backup? Only because the backup folder will contain the same folders but overtime backup will come in with the same file name. I was going to try and rename those that were copied into the backup folder

Thanks so much for you help!

Link to comment
Share on other sites

Yes, that is correct, however, I may see the confusion.  When I tested, I tested only against files, not sub-directories.  I'm thinking that michaelslamet is correct that when using dircopy with a destination within the source directory, only files will be copied, not folders.

Does that explain the behavior you are seeing?

 

Hey, this is a another relief :*

Link to comment
Share on other sites

Ah! ok that worked! Could you explain as to why you had to create a TempDir the move the TempDir to Backup? But great thanks! Is there a way to rename those folders after it's copied to the backup? Only because the backup folder will contain the same folders but overtime backup will come in with the same file name. I was going to try and rename those that were copied into the backup folder

Thanks so much for you help!

 

The answer was actually already provided by michaelslamet.  DirCopy doesn't seem to like it if your destination directory resides within your source directory, which makes sense.

 

Hi,

That is recursive. If you copy them to another folder, I think it should works:

DirCopy(@DesktopDir & "\Test", @DesktopDir & "\Backup", 1)

To answer your other question, just implement the date as you were already thinking

DirCopy(@DesktopDir & "\Test", @TempDir & "\MyTempDir", 1)
DirMove(@TempDir & "\MyTempDir", @DesktopDir & "\Test\Backup (" & @MON & "-" & @MDAY & "-" & @YEAR & ")", 1)
Link to comment
Share on other sites

Ah! ok that worked! Could you explain as to why you had to create a TempDir the move the TempDir to Backup? But great thanks! Is there a way to rename those folders after it's copied to the backup? Only because the backup folder will contain the same folders but overtime backup will come in with the same file name. I was going to try and rename those that were copied into the backup folder

Thanks so much for you help!

 

This is not tested, you can do it this way:

DirCopy(@DesktopDir & "\Test", @TempDir & "\MyTempDir", 1)
DirMove(@TempDir & "\MyTempDir", @DesktopDir & "\Test\Backup-" & @MON & "-" & @MDAY & "-"& @YEAR, 1)

That is assumed you're doing that (backup) once a day. If more than once a day, you can add some random number to the end of the folder name:

DirCopy(@DesktopDir & "\Test", @TempDir & "\MyTempDir", 1)
DirMove(@TempDir & "\MyTempDir", @DesktopDir & "\Test\Backup-" & @MON & "-" & @MDAY & "-"& @YEAR & "-" & Random(100000,999999,1), 1)

Those are untested, so please test it :)

Link to comment
Share on other sites

That is assumed you're doing that (backup) once a day. If more than once a day, you can add some random number to the end of the folder name

Could also be a good candidate for EPOCH time (seconds since start of 1970)

#include <Date.au3>
DirCopy(@DesktopDir & "\Test", @TempDir & "\MyTempDir", 1)
DirMove(@TempDir & "\MyTempDir", @DesktopDir & "\Test\Backup (" & _DateDiff('s', "1970/01/01 00:00:00", _NowCalc()) & ")", 1)

EDIT: We are here to flood you with working solutions :P

Edited by danwilli
Link to comment
Share on other sites

Could also be a good candidate for EPOCH time (seconds since start of 1970)

#include <Date.au3>
DirCopy(@DesktopDir & "\Test", @TempDir & "\MyTempDir", 1)
DirMove(@TempDir & "\MyTempDir", @DesktopDir & "\Test\Backup (" & _DateDiff('s', "1970/01/01 00:00:00", _NowCalc()) & ")", 1)

EDIT: We are here to flood you with working solutions :P

 

Using EPOCH time is much more better than random number, this is a new knowledge for me, thanks, danwilli! :)

Link to comment
Share on other sites

 

The answer was actually already provided by michaelslamet.  DirCopy doesn't seem to like it if your destination directory resides within your source directory, which makes sense.

To answer your other question, just implement the date as you were already thinking

DirCopy(@DesktopDir & "\Test", @TempDir & "\MyTempDir", 1)
DirMove(@TempDir & "\MyTempDir", @DesktopDir & "\Test\Backup (" & @MON & "-" & @MDAY & "-" & @YEAR & ")", 1)

This works! the only problem I notice is that when you run it creates Copies of the backup itsself. Instead of just copying all other folders then put them into the back up folder then rename it. I wonder if there is a way to copy all folders except The Back up and just create a new backup folder every time you run it 

Link to comment
Share on other sites

This is not tested, you can do it this way:

DirCopy(@DesktopDir & "\Test", @TempDir & "\MyTempDir", 1)
DirMove(@TempDir & "\MyTempDir", @DesktopDir & "\Test\Backup-" & @MON & "-" & @MDAY & "-"& @YEAR, 1)

That is assumed you're doing that (backup) once a day. If more than once a day, you can add some random number to the end of the folder name:

DirCopy(@DesktopDir & "\Test", @TempDir & "\MyTempDir", 1)
DirMove(@TempDir & "\MyTempDir", @DesktopDir & "\Test\Backup-" & @MON & "-" & @MDAY & "-"& @YEAR & "-" & Random(100000,999999,1), 1)

Those are untested, so please test it :)

 

I like the Random number! and it works - you guys are awesome in providing a bunch of working solutions! 

Link to comment
Share on other sites

  • Solution

 

This works! the only problem I notice is that when you run it creates Copies of the backup itsself. Instead of just copying all other folders then put them into the back up folder then rename it. I wonder if there is a way to copy all folders except The Back up and just create a new backup folder every time you run it 

Yes there are a lot of ways you could accomplish this behavior, but not with a simple dircopy().  You would be looking at looping through each directory and file and excluding what you do not want to copy.  You could easily alleviate this issue by creating the backup directories in any other location but the directory being backed up.

One of many possible examples

Local $sMyBackupDir = @DesktopDir & '\MyBackups'

_Backup(@DesktopDir & "\Test", $sMyBackupDir)

Func _Backup($sSource, $sDest)
    DirCopy(@DesktopDir & "\Test", $sDest & "\" & StringReplace(StringReplace($sSource, '\', '-'), ':', '') & " (" & @MON & "-" & @MDAY & "-" & @YEAR & ")", 1)
EndFunc   ;==>_Backup
Link to comment
Share on other sites

 

Yes there are a lot of ways you could accomplish this behavior, but not with a simple dircopy().  You would be looking at looping through each directory and file and excluding what you do not want to copy.  You could easily alleviate this issue by creating the backup directories in any other location but the directory being backed up.

One of many possible examples

Local $sMyBackupDir = @DesktopDir & '\MyBackups'

_Backup(@DesktopDir & "\Test", $sMyBackupDir)

Func _Backup($sSource, $sDest)
    DirCopy(@DesktopDir & "\Test", $sDest & "\" & StringReplace(StringReplace($sSource, '\', '-'), ':', '') & " (" & @MON & "-" & @MDAY & "-" & @YEAR & ")", 1)
EndFunc   ;==>_Backup

My knowledge continues to grow! Thanks for the help! I'm trying to read the Help File more and more :-p

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