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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleteery files with unknown file names. 1

Status
Not open for further replies.

MrMajik

IS-IT--Management
Apr 2, 2002
267
Using VB6...

I have a process running that generates 5 text files every minute of the day, 24 hrs a day. This generates a huge amount of files. Only files that are > 0 in size are worth keeping. Most files are empty.

Do you know how to delete a bunch of files solely by their file size? I only want to kill the empty files. All the files reside in the same folder. When completed this program will run one time each day as there will usually be at least 1400 of these text files to remove.

Thank you.
 
I would do something diferent. The program should create-write-close a txt file if there was something to write at all. I do not know what the fies contain, but before creating a file: (example). Do a trim to remove spaces and check the length of the variable you keep the strings ( len(stringname)<>0 ).


Hope that's helpful.
 
Hi TipGiver;

Thank you for replying. I am using a different (and cheezy) language that that came bundled with an application and does not offer that option. This is a very stripped down language with just enough features to get a little script program to run.

Any other ideas?

Thank you.
 
You could use the file system object to get a list of files in a folder, check the size, and then delete those that are 0.

Ex.

Code:
Dim FSO As Scripting.FileSystemObject
Dim oFolder As Scripting.Folder
Dim oFile As Scripting.File

Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = FSO.GetFolder("[!]C:\Folder\Sub Folder\[/!]")
Set FSO = Nothing

For Each oFile In oFolder.Files
    If oFile.Size = 0 Then
        Debug.Print oFile.Name
        Call oFile.Delete(True)
    End If
Next

Set oFolder = Nothing

I did not test this code after adding Call oFile.Delete(True) but it shoudl work just fine for you. Of course, you'll need to change the folder that this routine uses.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
gmmastros,

Thank you for replying.

I tried the code you posted in different arrangements. The 3 Dim statemenst are at the top and the rest of the code is inside this

Private Sub Command1_Click()
--code is here--
End Sub()

and keep getting this message:

Compiler error:
User-defined type not defined.

What is missing?

Thank you.
 
Yeah, sorry about that. I should have mentioned in my original response.

You need to add a reference to the scripting run-time control.

Click Project -> References
Scroll to Microsoft Scripting Runtime
Select it.



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
gmmastros,

That chunk of code you provided is exactly what I needed. Thank you for sharing!

MrMajik
 
I'm glad it's working for you, and thanks for the star.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Hello all,

I am trying to write something in vb.net that will delete all file exrentions (example *.mov) in all directories and subdirectories.

I know the "kill" command deletes the files. It only deletes files within the specified folder.

lately I have been cheating and having VB write batch files to do this.

can anyone help me with this?

I have looked in the msdn library and no luck

Thanks in advance
 
Well, if you are writing it in vb.net you probably ought to ask the question in the vb.net forum ...
 
In case you haven't found it : forum796

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top