Guest lca1630 Posted January 16, 2008 Posted January 16, 2008 Hi, I need help adding to my batch file a method of deleting any files over 7 days old. I want to run it as a scheduled task to clean up SQL express backup files. I'm still not sure why they eliminated the maintence stuff? Thanks for your help ahead of time. Here is my batch file so far: @Echo OFF @For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @( Set Month=%%A Set Day=%%B Set Year=%%C Set All=%%C%%A%%B ) @For %%a in ("*.bak") do copy %%a "E:\SQL Backups\%%~na - %%~na_%All%.bak"
Guest Pegasus \(MVP\) Posted January 16, 2008 Posted January 16, 2008 Re: Help with batch file!! File Cleanup "lca1630" <lca1630@discussions.microsoft.com> wrote in message news:0C9EA8D9-0E9A-425D-B1BA-325F859A73C3@microsoft.com... > Hi, > I need help adding to my batch file a method of deleting any files over 7 > days old. I want to run it as a scheduled task to clean up SQL express > backup > files. I'm still not sure why they eliminated the maintence stuff? Thanks > for > your help ahead of time. > > Here is my batch file so far: > > > > @Echo OFF > @For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @( > Set Month=%%A > Set Day=%%B > Set Year=%%C > Set All=%%C%%A%%B > ) > @For %%a in ("*.bak") do copy %%a "E:\SQL Backups\%%~na - %%~na_%All%.bak" You could add this line: xxcopy /db#7 /rs /yy /s *.bak c:\ You can download xxcopy.exe from a number of sites. By the way, you do not need any of your "@" characters other than the one in "@echo off". They serve no useful purpose other than confusing the code.
Guest lca1630 Posted January 16, 2008 Posted January 16, 2008 Re: Help with batch file!! File Cleanup Thanks Pegasus, I was having issues with this deleting the entire folder last week. Though I would post again. You gave me this example last week. xxcopy /db#7 /rs /yy /s "C:\Test\*.*" c:\ It deletes the entire test folder instead of the files inside which I can not have happen. Any more help you can give would be great. - Nik "Pegasus (MVP)" wrote: > > "lca1630" <lca1630@discussions.microsoft.com> wrote in message > news:0C9EA8D9-0E9A-425D-B1BA-325F859A73C3@microsoft.com... > > Hi, > > I need help adding to my batch file a method of deleting any files over 7 > > days old. I want to run it as a scheduled task to clean up SQL express > > backup > > files. I'm still not sure why they eliminated the maintence stuff? Thanks > > for > > your help ahead of time. > > > > Here is my batch file so far: > > > > > > > > @Echo OFF > > @For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @( > > Set Month=%%A > > Set Day=%%B > > Set Year=%%C > > Set All=%%C%%A%%B > > ) > > @For %%a in ("*.bak") do copy %%a "E:\SQL Backups\%%~na - %%~na_%All%.bak" > > You could add this line: > > xxcopy /db#7 /rs /yy /s *.bak c:\ > > You can download xxcopy.exe from a number of sites. > By the way, you do not need any of your "@" characters > other than the one in "@echo off". They serve no useful > purpose other than confusing the code. > > >
Guest Pegasus \(MVP\) Posted January 17, 2008 Posted January 17, 2008 Re: Help with batch file!! File Cleanup The directory c:\Test is deleted if it is empty after all files older than seven days are deleted. Adding the line if not exist c:\Temp md c:\Temp will restore the directory. "lca1630" <lca1630@discussions.microsoft.com> wrote in message news:98887FED-EE50-4BB0-A94D-C98654A63F1F@microsoft.com... > Thanks Pegasus, > > I was having issues with this deleting the entire folder last week. Though > I > would post again. You gave me this example last week. > > xxcopy /db#7 /rs /yy /s "C:\Test\*.*" c:\ > > It deletes the entire test folder instead of the files inside which I can > not have happen. Any more help you can give would be great. - Nik > > "Pegasus (MVP)" wrote: > >> >> "lca1630" <lca1630@discussions.microsoft.com> wrote in message >> news:0C9EA8D9-0E9A-425D-B1BA-325F859A73C3@microsoft.com... >> > Hi, >> > I need help adding to my batch file a method of deleting any files over >> > 7 >> > days old. I want to run it as a scheduled task to clean up SQL express >> > backup >> > files. I'm still not sure why they eliminated the maintence stuff? >> > Thanks >> > for >> > your help ahead of time. >> > >> > Here is my batch file so far: >> > >> > >> > >> > @Echo OFF >> > @For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @( >> > Set Month=%%A >> > Set Day=%%B >> > Set Year=%%C >> > Set All=%%C%%A%%B >> > ) >> > @For %%a in ("*.bak") do copy %%a "E:\SQL Backups\%%~na - >> > %%~na_%All%.bak" >> >> You could add this line: >> >> xxcopy /db#7 /rs /yy /s *.bak c:\ >> >> You can download xxcopy.exe from a number of sites. >> By the way, you do not need any of your "@" characters >> other than the one in "@echo off". They serve no useful >> purpose other than confusing the code. >> >> >>
Guest lca1630 Posted January 17, 2008 Posted January 17, 2008 Re: Help with batch file!! File Cleanup Thanks again, will you give me the complete command with the new part so that I have the correct syntax. Thansk for your help. - Nik "Pegasus (MVP)" wrote: > The directory c:\Test is deleted if it is empty after all files older > than seven days are deleted. Adding the line > > if not exist c:\Temp md c:\Temp > > will restore the directory. > > > "lca1630" <lca1630@discussions.microsoft.com> wrote in message > news:98887FED-EE50-4BB0-A94D-C98654A63F1F@microsoft.com... > > Thanks Pegasus, > > > > I was having issues with this deleting the entire folder last week. Though > > I > > would post again. You gave me this example last week. > > > > xxcopy /db#7 /rs /yy /s "C:\Test\*.*" c:\ > > > > It deletes the entire test folder instead of the files inside which I can > > not have happen. Any more help you can give would be great. - Nik > > > > "Pegasus (MVP)" wrote: > > > >> > >> "lca1630" <lca1630@discussions.microsoft.com> wrote in message > >> news:0C9EA8D9-0E9A-425D-B1BA-325F859A73C3@microsoft.com... > >> > Hi, > >> > I need help adding to my batch file a method of deleting any files over > >> > 7 > >> > days old. I want to run it as a scheduled task to clean up SQL express > >> > backup > >> > files. I'm still not sure why they eliminated the maintence stuff? > >> > Thanks > >> > for > >> > your help ahead of time. > >> > > >> > Here is my batch file so far: > >> > > >> > > >> > > >> > @Echo OFF > >> > @For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @( > >> > Set Month=%%A > >> > Set Day=%%B > >> > Set Year=%%C > >> > Set All=%%C%%A%%B > >> > ) > >> > @For %%a in ("*.bak") do copy %%a "E:\SQL Backups\%%~na - > >> > %%~na_%All%.bak" > >> > >> You could add this line: > >> > >> xxcopy /db#7 /rs /yy /s *.bak c:\ > >> > >> You can download xxcopy.exe from a number of sites. > >> By the way, you do not need any of your "@" characters > >> other than the one in "@echo off". They serve no useful > >> purpose other than confusing the code. > >> > >> > >> > > >
Guest Pegasus \(MVP\) Posted January 17, 2008 Posted January 17, 2008 Re: Help with batch file!! File Cleanup @echo off xxcopy /db#7 /rs /yy /s "C:\Test\*.*" c:\ if not exist c:\Test md c:\Test "lca1630" <lca1630@discussions.microsoft.com> wrote in message news:92468EEF-DF2C-4EF7-81BE-9AC9D3AF0485@microsoft.com... > Thanks again, will you give me the complete command with the new part so > that > I have the correct syntax. Thansk for your help. - Nik > > "Pegasus (MVP)" wrote: > >> The directory c:\Test is deleted if it is empty after all files older >> than seven days are deleted. Adding the line >> >> if not exist c:\Temp md c:\Temp >> >> will restore the directory. >> >> >> "lca1630" <lca1630@discussions.microsoft.com> wrote in message >> news:98887FED-EE50-4BB0-A94D-C98654A63F1F@microsoft.com... >> > Thanks Pegasus, >> > >> > I was having issues with this deleting the entire folder last week. >> > Though >> > I >> > would post again. You gave me this example last week. >> > >> > xxcopy /db#7 /rs /yy /s "C:\Test\*.*" c:\ >> > >> > It deletes the entire test folder instead of the files inside which I >> > can >> > not have happen. Any more help you can give would be great. - Nik >> > >> > "Pegasus (MVP)" wrote: >> > >> >> >> >> "lca1630" <lca1630@discussions.microsoft.com> wrote in message >> >> news:0C9EA8D9-0E9A-425D-B1BA-325F859A73C3@microsoft.com... >> >> > Hi, >> >> > I need help adding to my batch file a method of deleting any files >> >> > over >> >> > 7 >> >> > days old. I want to run it as a scheduled task to clean up SQL >> >> > express >> >> > backup >> >> > files. I'm still not sure why they eliminated the maintence stuff? >> >> > Thanks >> >> > for >> >> > your help ahead of time. >> >> > >> >> > Here is my batch file so far: >> >> > >> >> > >> >> > >> >> > @Echo OFF >> >> > @For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @( >> >> > Set Month=%%A >> >> > Set Day=%%B >> >> > Set Year=%%C >> >> > Set All=%%C%%A%%B >> >> > ) >> >> > @For %%a in ("*.bak") do copy %%a "E:\SQL Backups\%%~na - >> >> > %%~na_%All%.bak" >> >> >> >> You could add this line: >> >> >> >> xxcopy /db#7 /rs /yy /s *.bak c:\ >> >> >> >> You can download xxcopy.exe from a number of sites. >> >> By the way, you do not need any of your "@" characters >> >> other than the one in "@echo off". They serve no useful >> >> purpose other than confusing the code. >> >> >> >> >> >> >> >> >>
Guest lca1630 Posted January 17, 2008 Posted January 17, 2008 Re: Help with batch file!! File Cleanup Thank for your help "Pegasus (MVP)" wrote: > @echo off > xxcopy /db#7 /rs /yy /s "C:\Test\*.*" c:\ > if not exist c:\Test md c:\Test > > > "lca1630" <lca1630@discussions.microsoft.com> wrote in message > news:92468EEF-DF2C-4EF7-81BE-9AC9D3AF0485@microsoft.com... > > Thanks again, will you give me the complete command with the new part so > > that > > I have the correct syntax. Thansk for your help. - Nik > > > > "Pegasus (MVP)" wrote: > > > >> The directory c:\Test is deleted if it is empty after all files older > >> than seven days are deleted. Adding the line > >> > >> if not exist c:\Temp md c:\Temp > >> > >> will restore the directory. > >> > >> > >> "lca1630" <lca1630@discussions.microsoft.com> wrote in message > >> news:98887FED-EE50-4BB0-A94D-C98654A63F1F@microsoft.com... > >> > Thanks Pegasus, > >> > > >> > I was having issues with this deleting the entire folder last week. > >> > Though > >> > I > >> > would post again. You gave me this example last week. > >> > > >> > xxcopy /db#7 /rs /yy /s "C:\Test\*.*" c:\ > >> > > >> > It deletes the entire test folder instead of the files inside which I > >> > can > >> > not have happen. Any more help you can give would be great. - Nik > >> > > >> > "Pegasus (MVP)" wrote: > >> > > >> >> > >> >> "lca1630" <lca1630@discussions.microsoft.com> wrote in message > >> >> news:0C9EA8D9-0E9A-425D-B1BA-325F859A73C3@microsoft.com... > >> >> > Hi, > >> >> > I need help adding to my batch file a method of deleting any files > >> >> > over > >> >> > 7 > >> >> > days old. I want to run it as a scheduled task to clean up SQL > >> >> > express > >> >> > backup > >> >> > files. I'm still not sure why they eliminated the maintence stuff? > >> >> > Thanks > >> >> > for > >> >> > your help ahead of time. > >> >> > > >> >> > Here is my batch file so far: > >> >> > > >> >> > > >> >> > > >> >> > @Echo OFF > >> >> > @For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @( > >> >> > Set Month=%%A > >> >> > Set Day=%%B > >> >> > Set Year=%%C > >> >> > Set All=%%C%%A%%B > >> >> > ) > >> >> > @For %%a in ("*.bak") do copy %%a "E:\SQL Backups\%%~na - > >> >> > %%~na_%All%.bak" > >> >> > >> >> You could add this line: > >> >> > >> >> xxcopy /db#7 /rs /yy /s *.bak c:\ > >> >> > >> >> You can download xxcopy.exe from a number of sites. > >> >> By the way, you do not need any of your "@" characters > >> >> other than the one in "@echo off". They serve no useful > >> >> purpose other than confusing the code. > >> >> > >> >> > >> >> > >> > >> > >> > > >
Recommended Posts