Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

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 Dev Shed Forums Sponsor:
  #1  
Old January 27th, 2004, 09:03 PM
stromberg45 stromberg45 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 25 stromberg45 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to stromberg45
Lightbulb Old File deletion

Hi people, I haven't used the forum before but I've been told it can be extremely helpful. I'm only a novice/ intermediate programmer and am interested in developing my skills as much as I can. I have been asked to write a small program which will automatically run in the background of any terminal and delete files pre-year 2000. I have a rough example of what I've come up with so far. The best option I've come up with from the research done was to employ the FileSystemObject class. I think this will work fine, can anyone help me with my code? I haven't tested it yet, because I don't want to end up with no C:\...anyway have a look, any help would be greatly appreciated.

I put the 'real-code' within a timer, just ignore the timer, I still don't know how to execute programs without any commands needed.

Thankyou, Peter Ellis.

Dim fso As Scripting.FileSystemObject
Dim ts1 As Scripting.TextStream

Set fso = New Scripting.FileSystemObject

Dim PauseTime, Start, Finish, TotalTime
If (MsgBox("Press Yes to pause for 5 seconds", 4)) = vbYes Then
PauseTime = 5 ' Set duration.
Start = 10 ' Set start time.
Do While Timer < Start + PauseTime
If (fso.DriveExists("C")) Then
Set ts1 = fso.GetFile("C:\*.*").DateLastModified <= 1998
fso.DeleteFile (ts1)
MsgBox "Deleted old file" & fso.GetFileName
Set ts1 = Nothing
Else
MsgBox "NO - C:\ drive does not exist"
End If
Loop
Finish = 600 ' Set end time.
TotalTime = Finish - Start ' Calculate total time.
MsgBox "Paused for " & TotalTime & " seconds"
Else
End
End If

Set ts1 = Nothing
Set fso = Nothing


Reply With Quote
  #2  
Old January 27th, 2004, 10:00 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,193 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 13 h 55 m 17 sec
Reputation Power: 142
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
it looks as though it might work, but do this. Set your clock on your computer back to 1997. Then set up a folder and fill it with empty text files. Then set up your program to run in that folder, and let it work it's magic. As far as running your program in the background, there are two ways I can suggest.
1. Schedule a task using windows task scheduler with a command line argument (like a or something - to signify automatic). Then, capture that value in form-load. If you have a value, then you hide the form and clear any errors that may arise. This approach allows the program to run in a default mode with no visible interface, or you can build in controls in case the user opens the program from the icon.
2. There are API Calls you can use to run a program as a service. This doesn't allow the flexibility I metioned before, but it does work well.

I like the first method, and have written several programs this way, but it requires extra programming, and some programmers don't like to do it.

Good luck

Reply With Quote
  #3  
Old January 28th, 2004, 08:14 PM
stromberg45 stromberg45 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 25 stromberg45 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to stromberg45
thanks very much for your help. i'll post my results.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Old File deletion


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT