Macro to Look for Filenames that don't match the format

AlexH

New Member
Joined
Dec 11, 2012
Messages
17
One of the programs we use at work creates a data file that lists filenames of information files that we use to scan in the work we've done that day. However, some of the work we do can't be logged in this way, but is still in the data file. The file name of a good file looks like "m:\trumpf9\ncdone\rueck685.txt:DA,'5969','596993','596909300',11,11,2210,'' while a bad one looks like anything except this, for instance "m:\trumpf9\ncdone\rueck686.txt:DA,'CP_TAPESHOT',1". Is there anyway to make a macro that will kill any file that doesn't match the format of the first filename? Also, some of the files have an extra "'0'," at the end of the string, or they have some of the numbers replaced by "'*'," so I'm not sure how to work around those problems.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
m:\trumpf9\ncdone\rueck685.txt That's the file path. The other stuff is just data. The actual filename is rueck685.txt
 
Upvote 0
I know this is a old post, but I did not see a solution.
If you still needed a solution, it appears to me that you want to read the contents of the text file and not necessarily the file name.
if this true then hopefully this will assist you.
Code:
Option Explicit
Sub TextReader()
Dim StrFileNM       As String
Dim StrLine         As String
Dim LFileNum        As Long
     
StrFileNM = "C:\SAMPLE.TXT"
LFileNum = FreeFile
    Close LFileNum
    Open StrFileNM For Input As LFileNum
    Do While Not EOF(LFileNum)
        Line Input #LFileNum, StrLine
        Debug.Print StrLine
    Loop
End Sub
Once you identify the file you wish to delete "KILL" then you can use this
Code:
Private Sub DeleteFile()
Dim StrFileNM As String
StrFileNM = "C:\SAMPLE.TXT"
Kill StrFileNM

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,206,921
Messages
6,075,578
Members
446,147
Latest member
homedecortips

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top