What did the message box say about the number of days? Modify the msg variable to say: msg = "Old Files: " & OldDate
which should give the date 10/1/2011. we may want to change the display of the DateDiff to "0000.00" to see if perhaps it's including the "time" The olddate would be counted as midnight. The filedate like 10/1/2011 @ 9:00am would be equivalent to 40817.375, so the difference would be .375, which would be > 0, so it wouldn't select it. The SIMPLEST change would be to test it <=1 instead of <=0 but I'd still prefer to know WHY it's doing it. Paul ----------------------------------------- “Do all the good you can, By all the means you can, In all the ways you can, In all the places you can, At all the times you can, To all the people you can, As long as ever you can.” - John Wesley ----------------------------------------- ________________________________ From: Dave <davidstev...@gmail.com> To: MS EXCEL AND VBA MACROS <excel-macros@googlegroups.com> Sent: Tue, November 1, 2011 11:32:06 AM Subject: Re: $$Excel-Macros$$ Copy Files & then go back amd delete them Paul, The script you wote is great. I just did not know that you could do all the actions in one step. I ran the script and here is what its doing. In the "From" directory I have files that were created between 9/1/2011 & 9/30/2011 your program moved them all correctly. Than there were files that were created from 10/01/2011 to 10/31/2011 your program did not move them at all (even though they are > 1 month old today being 11/01/2011) I will run this script end of every month and so I want files from the previous months copied over to the destination directory. So in my example all files from 9/1/2011 to 10/31/2011 and leave behind files created 11/01/2011 & greater (untill the next month when these files will be picked up) Thanks to everyone for doing a great job and helping me on this matter. On Nov 1, 9:02 am, Paul Schreiner <schreiner_p...@att.net> wrote: > Do you REALLY want it to run in two separate steps? > (Copy all old files, then remove all old files) > Or can it copy/check/remove in one loop? > Option Explicit > Sub Archive_Files() > Dim fso, fldr, flc, f, fName, Fil, fDate > Dim OldDate > Dim Folder_From, Folder_To > Dim msg, msg2 > > '----------------------------------------------------------------------------- > Folder_From = "N:\from\" 'Note: trailing "\" is significant! > Folder_To = "N:\to\" > > '----------------------------------------------------------------------------- > Set fso = CreateObject("Scripting.FileSystemObject") > OldDate = DateAdd("m", -1, Now()) 'Determines date 1 month ago > msg = "Old Files: " > msg2 = "Recent Files:" > > '----------------------------------------------------------------------------- > If fso.folderexists(Folder_From) Then > '------------------------------------------------------ > Set fldr = fso.getfolder(Folder_From) > Set flc = fldr.Files > For Each f In flc > fName = Folder_From & "\" & f.Name > Set Fil = fso.getfile(fName) > fDate = Fil.datelastmodified > If (DateDiff("d", OldDate, fDate) <= 0) Then > msg = msg & Chr(13) & Format(DateDiff("d", OldDate, fDate), > "0000") & " " & Format(fDate, "mm-dd-yyyy") & " " & f.Name > fso.copyfile fName, Folder_To > If (fso.fileexists(Folder_To & f.Name)) Then > fso.deletefile (fName) > End If > Else > msg2 = msg2 & Chr(13) & Format(DateDiff("d", OldDate, fDate), > "0000") & " " & Format(fDate, "mm-dd-yyyy") & " " & f.Name > End If > Next > MsgBox msg & Chr(13) & Chr(13) & msg2 > End If > End Sub > > If you don't like the Message box "reporting" results, simply comment it out. > > If you insist on copying the files, then going back to delete them, let me know > and I'll break it into two functions. > > Paul > ----------------------------------------- > “Do all the good you can, > By all the means you can, > In all the ways you can, > In all the places you can, > At all the times you can, > To all the people you can, > As long as ever you can.” - John Wesley > ----------------------------------------- > > ________________________________ > From: Dave <davidstev...@gmail.com> > To: MS EXCEL AND VBA MACROS <excel-macros@googlegroups.com> > Sent: Tue, November 1, 2011 9:03:43 AM > Subject: Re: $$Excel-Macros$$ Copy Files & then go back amd delete them > > Thanks Ashish, > > But the program is not working , when I pick the source directory I > get an error saying "Permission Denied" and when you click on the > debugger the following line is highlighted in the code. > fso.Copyfile fil.Path, Sheets(1).Range("b1").Value > > What I want from the program is as follows. > My source directory is always going to be P:\from & my target is > going to be P:\to. I want the program to select all files that are 1 > month old from P:\A and copy them into P:\B. Then I want the program > to verify if the files are copied and then once the verification is > complete than go back to P:\from and delete the 1 month old files. > > I dont want the user to be able to select the source and destination > directories etc. Just when they click on a button the program does the > above and gives a message when the operation is complete. > > thanks for your time and effort. > > On Nov 1, 2:56 am, ashish koul <koul.ash...@gmail.com> wrote: > > > > > > > Hi Dave, > > > try the attachment > > > On Tue, Nov 1, 2011 at 1:00 AM, Dave <davidstev...@gmail.com> wrote: > > > Hi, > > > > I need help with the following task. Thanks in advance > > > I am using MS Excel 2010. > > > > I have two folders: A & B. I want to do the folllowing tasks > > > > 1, Every month I want to copy all files that are 1 month old (these > > > are all .PDF files) from folder A to folder B. > > > 2, Then I want to verify if the files are copied correctly . > > > 3, Then once the copied files are verifiied I want to delete all the > > > original files from A. > > > > It has to be a copy and not a move operation as my network privelages > > > get screwed up when I move the files. > > > > Thanks , > > > > Dave > > > > -- > > > FORUM RULES (925+ members already BANNED for violation) > > > > 1) Use concise, accurate thread titles. Poor thread titles, like Please > > > Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice > > > will not get quick attention or may not be answered. > > > > 2) Don't post a question in the thread of another member. > > > > 3) Don't post questions regarding breaking or bypassing any security > > > measure. > > > > 4) Acknowledge the responses you receive, good or bad. > > > > 5) Cross-promotion of, or links to, forums competitive to this forum in > > > signatures are prohibited. > > > > NOTE : Don't ever post personal or confidential data in a workbook. Forum > > > owners and members are not responsible for any loss. > >>------------------------------------------------------------------------------------------------------ >- > > > > To post to this group, send email to excel-macros@googlegroups.com > > > -- > > *Regards* > > * * > > *Ashish Koul* > > *http://www.excelvbamacros.com/* > > > P Before printing, think about the environment. > > > copy files from folder.xls > > 50KViewDownload- Hide quoted text - > > > - Show quoted text - > > -- > FORUM RULES (925+ members already BANNED for violation) > > 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, > Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get > quick attention or may not be answered. > > 2) Don't post a question in the thread of another member. > > 3) Don't post questions regarding breaking or bypassing any security measure. > > 4) Acknowledge the responses you receive, good or bad. > > 5) Cross-promotion of, or links to, forums competitive to this forum in > signatures are prohibited. > > NOTE : Don't ever post personal or confidential data in a workbook. Forum > owners and members are not responsible for any loss. > >------------------------------------------------------------------------------------------------------ >- > > To post to this group, send email to excel-macros@googlegroups.com- Hide > quoted >text - > > - Show quoted text - -- FORUM RULES (925+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. ------------------------------------------------------------------------------------------------------ To post to this group, send email to excel-macros@googlegroups.com -- FORUM RULES (925+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. ------------------------------------------------------------------------------------------------------ To post to this group, send email to excel-macros@googlegroups.com