|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 ![]() |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
thanks very much for your help. i'll post my results.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Old File deletion |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|