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

Kill Command Issue 1

Status
Not open for further replies.

proximity

Technical User
Sep 19, 2002
132
GB
Hi,

I have a directoy with text files:

123456.txt
882121.txt
854452.txt

They can have any combination of numbers but are never more nor less than 6 characters long.

In the same directory there are files like: newreport.txt
and latestupdate.txt In other words, just your bog standard text files with no numbers in the name.

How do I use the KILL command to delete only those txt files that DO NOT have numbers in their name?

I have tried may things but can't seem to crack this seemingly easy problem?!

EG, the code below delets the files with numers in the names:

Sub KILLTEST()
Dim C As String
C = "??????.txt"
Kill "H:\Distribution\Reports\Prod\" & C
End Sub

 
Code:
Dim FileName As String
Dim DirName  As String
DirName = "H:\Distribution\Reports\Prod\"
FileName = Dir(DirName & "*.txt")
Do While Len(FileName) > 0
   If IsNumeric(Left(FileName,Len(FileName)-4)) Then
      Kill DirName & FileName
   End If
   FileName = Dir()
Loop
 
Oops ... sorry
Code:
Dim FileName As String
Dim DirName  As String
DirName = "H:\Distribution\Reports\Prod\"
FileName = Dir(DirName & "*.txt")
Do While Len(FileName) > 0
   If [red]NOT[/red] IsNumeric(Left(FileName,Len(FileName)-4)) Then
      Kill DirName & FileName
   End If
   FileName = Dir()
Loop
 
Thanks Golom,

That worked a treat !

All the best,

--
Steven
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top