Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need some help with a Login script

Status
Not open for further replies.

jvilla1983

Programmer
Dec 19, 2007
3
US
Hi, my name is Joseph. I'm looking for some help with editing a login script that was created with VBscript.

What I'm trying to accomplish is to search through a certain folder and find files older than 90 days. I keep thinking that I'm should do this with an array or a loop, but I know that scripting is a different animal than other high level languages.

This is what I have so far..


sub deleteReallyOldFiles()

' Connecting the "I" drive
objNet.MapNetworkDrive "I:", "\\xxxxxxxxx0002\ITS"


date_mod=Date-90
Set FSO = CreateObject("Scripting.FileSystemObject")
For Each SubFiles in FSO.GetFolder("I:\AutomatedManualBackup\user.id\").Files
IF SubFiles.DateLastModified <= date_mod Then
Wscript.Echo SUbFiles.Name
SubFiles.Delete
End IF

' Disconnecting the "I" drive
objNet.RemoveNetworkDrive "I:", true, true

End Sub

I'm getting an error on the End Sub and I have no idea why.

Thanks in advance for any help..

Joseph Villa
 
You're missing the NEXT that goes along with the For Each

For Each xxxx

Next

objNet.Removexxxx
End Sub

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Ok I had editied the file and changed from looking at the date modified to the date created.

Here is what I have now...


Sub deleteOldFiles()

' Connecting the "I" drive
objNet.MapNetworkDrive "I:", "\\igsbcccmgs0002\ITS"

date_del= 90
Set FSO = CreateObject("Scripting.FileSystemObject")
For Each SubFiles in FSO.GetFolder("I:\AutomatedManualBackup\user.id\").Files
IF objFile.DateCreated < (Date() - date_del) Then
objFile.Delete
End IF
Next

' Disconnecting the "I" drive
objNet.RemoveNetworkDrive "I:", true, true

End Sub

Now the problem is that its not deleting the files that i have which I changed the date on to be more than 90 days. Is there anything that i'm missing here if I'm just going through a file with no subfolders?
 
after: Set FSO = CreateObject("Scripting.FileSystemObject")

try this:

set objFolder = FSO.GetFolder("I:\AutomatedManualBackup\user.id\").Files

For Each objFile in objFolder
If objfile.DateCreated < Date()-90 Then
objFile.Delete
End if
next

worked for me when I tested it in a dummy location

if not you might check privileges, if the path is correct, if the drive is always mapped at the time the script runs etc

HTH

Sg284
 
Take a look at my CleanbadMail script included in my FAQ faq955-6503.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top