| 1. |
Solve : Delete by date modified? |
|
Answer» What is the command to delete files by date modified? Reply #1 will find the files older than five days. Why not just tell forfiles to delete the files older than 5 days? I know you like redirecting, Bill, but it is not necessary in this case. I suspect Bill just found out about forfiles and logged in as a DIFFERENT user to ask a "question" that he could proceed to "answer" as donald99, who therefore won't complain that his question was not answered properly. The original question asked how to delete all files in a folder older than 5 days. Bill showed how to use forfiles to make a file containing a list of .bat files in a folder and all subfolders under it, that were older than 4 days. He then issued a vague suggestion to "use a for loop" to delete those files. Ah the "for loop" - forever beyond Bill's comprehension. However it may be that somebody sometime might really want to know how to use the forfiles command to delete files older than a certain age (Google please index here!). This can be done all in one line so a script may not even be necessary. Let's build the command... 1. We type forfiles and a space (which you can't see yet, but it's there. Trust me.) FORFILES 2. Next we add the /M switch with a file mask to show what files to delete - "all files" was asked for so we use *.* and another space. FORFILES /M *.* 3. Next we add the date switch /D with a space and then a negative number and then another space. This number tells forfiles to select files with a modified date less than or equal to today's date minus that number of days. This means that if you put /D -5 you will select all those files which were modified more than 4 days ago. So take care here. Since the OP asked how to delete files "with a modified date older than 5 days", the correct number would be -6. FORFILES /M *.* /D -6 4. Now we add the /C switch and a space to tell forfiles that what is coming next is a command string. FORFILES /M *.* /D -6 /C 5. At last we can specify the command which we want to perform on these selected files. To delete the file we specify CMD with the /C switch, followed by a space then DEL and a space and finally FILE and we put the whole lot in double quotes. FORFILES /M *.* /D -6 /C "CMD /C DEL FILE" There you are. Finished. Although I have used upper case in fact you can use lower case, or a mixture. Quote from: Salmon Trout on December 19, 2010, 01:52:11 AM Why not just tell forfiles to delete the files older than 5 days? I know you like redirecting but it is not necessary in this case. I was unable to test the delete function of forfiles. But it should work. Thanks for the suggestion p.s The for loop is an option. Quote from: donald99 on December 19, 2010, 04:13:46 AM I was unable to test the delete function of forfiles. But it should work. Oh right! It should work. That is reassuring. Did Bill Gates tell you that himself? You don't mind me calling you Bill, do you? Quote from: Salmon Trout on December 19, 2010, 04:14:47 AM Salmon Trout, Please show us the CODE and an output sample for the "delete by date modified" forfiles code. Thanks for your help. p.s. forfiles /? Quote from: donald99 on December 19, 2010, 04:21:09 AM Salmon Trout, I already showed the one line of code. There is no "output". Maybe time to lock this thread, prior to banning Bill again? Quote from: Salmon Trout on December 19, 2010, 04:07:57 AM The original question asked how to delete all files in a folder older than 5 days. Salmon Trout, Where is a sample of FORFILES /M *.* /D -6 /C "CMD /C DEL FILE" output? Quote from: donald99 on December 19, 2010, 04:33:00 AM Salmon Trout, There isn't any. The "output" is the deletion of the files. Please quit trolling. ST wrote: "There isn't any. The "output" is the deletion of the files." Maybe a notice from the OS that the files were deleted successfully? p.s. OS means Operating System Quote from: donald99 on December 19, 2010, 04:51:41 AM
Well, I leave that as an exercise for the reader. In any case deletion can be verified by inspection. Or by running the command a second time and verifying that the message "ERROR: No files found with the specified search CRITERIA." is seen. Or by doing DIR before and after. Successly? What language is that? What part of "please quit trolling" did you fail to comprehend? You wanted output... Code: [Select]S:\Test\forfiles-del>forfiles /M *.* /D -6 /C "cmd /c echo delete fdate file & del file" delete 07/12/2010 "TestFile001.zip" delete 07/12/2010 "TestFile002.zip" delete 08/12/2010 "TestFile003.rar" delete 10/12/2010 "TestFile005.exe" delete 03/12/2010 "TestFile006.PDF" delete 06/12/2010 "TestFile007.nzb" delete 06/12/2010 "TestFile008.nzb" delete 13/12/2010 "TestFile009.nzb" delete 07/12/2010 "TestFile010.zip" delete 11/12/2010 "TestFile011.nzb" delete 05/12/2010 "TestFile012.nzb" delete 10/12/2010 "TestFile013.nzb" delete 03/12/2010 "TestFile016.PDF" delete 03/12/2010 "TestFile017.PDF" delete 10/12/2010 "TestFile019.zip" delete 01/12/2010 "TestFile020.zip" delete 11/12/2010 "TestFile024.zip" delete 05/12/2010 "TestFile025.zip" delete 01/12/2010 "TestFile027.zip" delete 05/12/2010 "TestFile028.exe" delete 11/12/2010 "TestFile029.exe" S:\Test\forfiles-del>forfiles /M *.* /D -6 /C "cmd /c echo delete fdate file & del file" ERROR: No files found with the specified search criteria. S:\Test\forfiles-del> Define Troll: "Online false statement used as Internet lure: a carefully worded but incorrect statement that is designed to lure other Internet users into sending responses." http://www.bing.com/Dictionary/search?q=define+troll&FORM=DTPDIA&qpvt=define+troll p.s. I cannot find any posts by Donald99 that fits the above definition |
|