Windows Scripting
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsSystem AdministrationWindows Scripting

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 26th, 2007, 10:24 PM
no1ncf no1ncf is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Location: Charlotte, NC
Posts: 3 no1ncf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 51 sec
Reputation Power: 0
Send a message via AIM to no1ncf Send a message via MSN to no1ncf Send a message via Yahoo to no1ncf
WSH - Copying/Deleting files from one server to another.

Ok.......first let me explain I am not a scripting guru........but always willing to learn.

I have a server that creates a DB backup to the local file system in two different locations. The DB backup alternates between the two different folders.

Now, I have a batch file that copies the contents of the (DB backup) folders to a mapped network drive on another server. The batch file creates a folder based on the current date, and copies the DB files into that date-named folder. However, I frequently run out of space.......as the batch file runs twice daily, every day.

What I am needing to do, is execute something in the batch file that deletes the copied folders that are older than X amount of days. And to have this done prior to the copying of the current days files.

I know this has to be possible, and am sure it is something simple. However, I am not as savvy with this stuff as most of you folks.

Thanks in advance for your expertise!
Bob

Reply With Quote
  #2  
Old January 27th, 2007, 01:44 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,048 Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Days 12 h 32 m 33 sec
Reputation Power: 555
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo
MySpace
Hey, no1ncf,

I'll tell you like I tell most people. This is much easier to do using WSH than it is in batch. WSH provides much more flexibility and has a lot more built-in functions for working on remote computers. It also runs more efficiently which means that it will typically run faster than batch. Simply put, the easiest way to accomplish this in batch is with the help of a third-party program. There are several available for download that can delete files and folders based on date. If you're interested in a WSH approach, let me know.
__________________
Click the image if at any point you don't like my decision.

Scripting problems? Windows questions? Ask the Windows Guru!


Reply With Quote
  #3  
Old January 28th, 2007, 11:59 AM
no1ncf no1ncf is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Location: Charlotte, NC
Posts: 3 no1ncf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 51 sec
Reputation Power: 0
Send a message via AIM to no1ncf Send a message via MSN to no1ncf Send a message via Yahoo to no1ncf
I am into using whatever is easier..........Let me know what I need to do in order to get it to work thru WSH.

THANKS!!!!
Bob

Reply With Quote
  #4  
Old January 29th, 2007, 12:26 AM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,048 Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Days 12 h 32 m 33 sec
Reputation Power: 555
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo
MySpace
Let me get a working model for us to work from and we'll customize it to your needs.

Reply With Quote
  #5  
Old January 30th, 2007, 08:39 PM
no1ncf no1ncf is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Location: Charlotte, NC
Posts: 3 no1ncf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 51 sec
Reputation Power: 0
Send a message via AIM to no1ncf Send a message via MSN to no1ncf Send a message via Yahoo to no1ncf
Pardon my ignorance........But what do you mean by a working model??

Are you wanting the specs or the current batch file that I am using??

Thanks again...............

Reply With Quote
  #6  
Old January 30th, 2007, 10:43 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,048 Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Days 12 h 32 m 33 sec
Reputation Power: 555
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo
MySpace
By working model, I meant a working script that we could tweak to your specific needs.

If you could post your batch file, that would help greatly.

Reply With Quote
  #7  
Old April 2nd, 2007, 01:07 PM
sharonp sharonp is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 sharonp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 32 sec
Reputation Power: 0
Deleting Files

Hello,

I too am interested in knowing how to code WSH to delete files that are n days old. Would you share your solution with me also?

Regards,
Sharonp

Reply With Quote
  #8  
Old April 2nd, 2007, 01:13 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,048 Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Days 12 h 32 m 33 sec
Reputation Power: 555
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo
MySpace
I'm short on time at the moment, but I throw up a basic script for this shortly.

Reply With Quote
  #9  
Old April 9th, 2007, 08:12 PM
JamesLe JamesLe is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Oakland, CA, USA
Posts: 131 JamesLe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m
Reputation Power: 5
Quote:
Originally Posted by sharonp
Hello,

I too am interested in knowing how to code WSH to delete files that are n days old. Would you share your solution with me also?

Regards,
Sharonp



This post may help!

Automatic File Delete

Reply With Quote
  #10  
Old April 9th, 2007, 11:33 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,048 Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Days 12 h 32 m 33 sec
Reputation Power: 555
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo
MySpace
Here's a simple function that will delete a file if it is older than a given number of days. I've written both examples below to run against your Windows Temp folder so feel free to give them a test run.

Set the numDays variable equal to the number of days to check. I've included it in the function so you can effectively change it every time you call it. (Maybe different folders should be checked against different dates.)

This script will check all files in a specified folder....
Code:
numDays = 7
strPath = "C:\Windows\Temp"

Set objfso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objfso.GetFolder(strPath)
Set colFiles = objFolder.Files
For Each objFile In colFiles
	DeleteOldFile objFile, numDays
Next

Function DeleteOldFile(objFile, numDays)
	On Error Resume Next
	dateFile = objFile.DateLastModified
	dateToday = Date()
	' dateToday = Now() will also work
	If dateFile <= dateToday Then
		daysOld = dateToday - dateFile
		If daysOld > numDays Then
			strFile = objFile.Name
			objFile.Delete
			If objFile Then
				WScript.Echo "Could not delete", strFile
			End If
		End If
	Else
		WScript.Echo "The script has detected an incorrect date stamp."
	End If
End Function
Variations:

If want to perform a recursive delete for subfoldes as well, use the script below:
Code:
numDays = 7
strPath = "C:\Windows\Temp"

Set objfso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objfso.GetFolder(strPath)
' Use True to perform a recursive delete, False if not
CheckFolder objFolder, numDays, True

Function CheckFolder(objFolder, numDays, bRecurse)
	Set colFiles = objFolder.Files
	If colFiles.Count > 0 Then
		For Each objFile In colFiles
			DeleteOldFile objFile, numDays
		Next
	End If
	If bRecurse Then
		Set colSubfolders = objFolder.SubFolders
		If colSubfolders.Count > 0 Then
			For Each SubFolder In colSubfolders
				CheckFolder SubFolder, numDays, True
			Next
		End If
	End If
End Function

Function DeleteOldFile(objFile, numDays)
	On Error Resume Next
	dateFile = objFile.DateLastModified
	' You may wish to use:
	' dateFile = objFile.DateLastAccessed
	' DateLastModified only reflects saved changes
	dateToday = Date()
	' dateToday = Now() will also work
	If dateFile <= dateToday Then
		daysOld = dateToday - dateFile
		If daysOld > numDays Then
			strFile = objFile.Path
			objFile.Delete
			If objFile Then
				WScript.Echo "Could not delete", strFile
			End If
		End If
	Else
		WScript.Echo "The script has detected an incorrect date stamp."
	End If
End Function
To delete all files, just use numDays = -1. Using numDays = 0 would preserve anything modified today.

Hope this helps.

Reply With Quote
  #11  
Old April 9th, 2007, 11:58 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,048 Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Days 12 h 32 m 33 sec
Reputation Power: 555
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo
MySpace
Note that the scripts above will not delete read-only/hidden/system files or files that are currently in use. If you would like to add this functionality let me know.

Reply With Quote
  #12  
Old April 17th, 2007, 09:27 AM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,048