Go Back   TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: ,

Sponsored Links



Help with batch file!! File Cleanup

Windows Server Help


Reply
 
Thread Tools Search this Thread
  #1  
Old 17-01-2008
lca1630
 
Posts: n/a
Help with batch file!! File Cleanup

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"
Reply With Quote
  #2  
Old 17-01-2008
Pegasus \(MVP\)
 
Posts: n/a
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.


Reply With Quote
  #3  
Old 17-01-2008
lca1630
 
Posts: n/a
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.
>
>
>

Reply With Quote
  #4  
Old 17-01-2008
Pegasus \(MVP\)
 
Posts: n/a
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.
>>
>>
>>



Reply With Quote
  #5  
Old 17-01-2008
lca1630
 
Posts: n/a
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.
> >>
> >>
> >>

>
>
>

Reply With Quote
  #6  
Old 17-01-2008
Pegasus \(MVP\)
 
Posts: n/a
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.
>> >>
>> >>
>> >>

>>
>>
>>



Reply With Quote
  #7  
Old 17-01-2008
lca1630
 
Posts: n/a
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.
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>

>
>
>

Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Help with batch file!! File Cleanup"
Thread Thread Starter Forum Replies Last Post
make file name list in excel using batch file shibinpanayi Windows Software 1 04-06-2011 04:44 AM
Windows Batch file to output directory names and size to txt file m2thearkus Software Development 6 16-07-2010 01:04 AM
How can I play a sound file from a Windows batch file? Linoo Operating Systems 4 27-03-2010 08:20 PM
Dos batch file to sort files based on file names. Jon Osborn Windows Server Help 9 17-06-2009 12:06 PM
Batch file to copy a file from the local drive to a computer on lan? dudelearn Tips & Tweaks 3 12-03-2009 01:56 PM


All times are GMT +5.5. The time now is 01:24 AM.