swstrau118 Posted July 3, 2013 Share Posted July 3, 2013 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 More sharing options...
michaelslamet Posted July 3, 2013 Share Posted July 3, 2013 Hi, That is recursive. If you copy them to another folder, I think it should works: DirCopy(@DesktopDir & "\Test", @DesktopDir & "\Backup", 1) Link to comment Share on other sites More sharing options...
DW1 Posted July 3, 2013 Share Posted July 3, 2013 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 AutoIt3 Online Help Link to comment Share on other sites More sharing options...
michaelslamet Posted July 3, 2013 Share Posted July 3, 2013 Your code as it sits, works exactly as expected for me. Win 7 x64 AutoIt 3.3.8.1 Duh, I'm emberrace that everytime I try to help, mine is incorrect and/or there are another better solutions Link to comment Share on other sites More sharing options...
DW1 Posted July 3, 2013 Share Posted July 3, 2013 Duh, I'm emberrace that everytime I try to help, mine is incorrect and/or there are another better solutions Happens to all of us, no worries AutoIt3 Online Help Link to comment Share on other sites More sharing options...
michaelslamet Posted July 3, 2013 Share Posted July 3, 2013 Happens to all of us, no worries Thanks, danwilli, that is a relief Link to comment Share on other sites More sharing options...
swstrau118 Posted July 4, 2013 Author Share Posted July 4, 2013 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 More sharing options...
DW1 Posted July 4, 2013 Share Posted July 4, 2013 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? AutoIt3 Online Help Link to comment Share on other sites More sharing options...
DW1 Posted July 4, 2013 Share Posted July 4, 2013 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) AutoIt3 Online Help Link to comment Share on other sites More sharing options...
swstrau118 Posted July 4, 2013 Author Share Posted July 4, 2013 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 More sharing options...
michaelslamet Posted July 4, 2013 Share Posted July 4, 2013 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 DW1 1 Link to comment Share on other sites More sharing options...
DW1 Posted July 4, 2013 Share Posted July 4, 2013 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) AutoIt3 Online Help Link to comment Share on other sites More sharing options...
michaelslamet Posted July 4, 2013 Share Posted July 4, 2013 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 More sharing options...
DW1 Posted July 4, 2013 Share Posted July 4, 2013 (edited) 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 Edited July 4, 2013 by danwilli michaelslamet 1 AutoIt3 Online Help Link to comment Share on other sites More sharing options...
michaelslamet Posted July 4, 2013 Share Posted July 4, 2013 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 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 More sharing options...
swstrau118 Posted July 4, 2013 Author Share Posted July 4, 2013 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 More sharing options...
michaelslamet Posted July 4, 2013 Share Posted July 4, 2013 I know that question will finally arised '?do=embed' frameborder='0' data-embedContent>> btw, why not backup to another folder, why use recursive folder? Backup to another folder will not include the previous backup DW1 1 Link to comment Share on other sites More sharing options...
swstrau118 Posted July 4, 2013 Author Share Posted July 4, 2013 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! DW1 1 Link to comment Share on other sites More sharing options...
Solution DW1 Posted July 4, 2013 Solution Share Posted July 4, 2013 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 AutoIt3 Online Help Link to comment Share on other sites More sharing options...
swstrau118 Posted July 4, 2013 Author Share Posted July 4, 2013 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now