Deleting Text Files using VB

I remember quite a few years ago now going for an interview and was being given the guided tour of the business and in this large loading bay come warehouse, one was was stacked floor to ceiling with large boxes of various shapes and sizes all fully loaded with what looked like post cards.

As a Health and Safety person I asked what they contained, and was given the reply "they are customer registration cards for various applicances. There must be over a million there." And before you ask, No, they were not stored electronically anywhere and they had no means of finding one at all if they needed to.

So much for filling out those little post coards you get with your toaster.
 
the thing about the serial numbers that made me come to that conclusion was the stock position

if curry's say (Mayor UK distrubutor - not sure where you are, John) have a number of cookers, i came to the conclusion that they couldnt possible know that the customer who bought one bought a particular serial no - otherwise the stock system just couldnt handle it (well just maybe they could scan something on the box outer).

But on this basis I assumed they didnt even care - if warranty work was needed you had to produce your proof or purchase - and if the customer registered the warranty, that would tick off a list somewhere.

-----------
contrast this with blockbusters (dvd rentals) - or indeed possibly any lending library) I have come to the conclusion here that the bar code on a film uniquely identifies the indivdiual copy of the film, not just the film itself - maybe the barcode is tied to a unique serial no burnt ON THE DVD

ie mamma mia, copy 7, or mamma mia, copy 8

otherwise you couldnt just return a film without an id - as they wouldnt know which user was returning the film

--------
thinking about uniqueness of otherwise homogeneous items is quite a tricky area methinks
 
Hi Gemma,

Well that's not a million miles away from what currently happens with the company I work for, the only difference is that once we have captured the information from the registration cards, we actually destroy them within 5 days. We mail out customers within 30 days of registration and again at the 11 month point, which is a month before the normal manufacturer's guarantee period expires, but where manufacturer's have given two or five year guarantee's we mail them out one month before those periods expire. For processing purposes we keep the text files for a maximum of 6 months, along with their images just in case customers contact us for whatever reason with regards to their registrations. We have found no requirement to keep them longer than that, and also to maintain our Data Protection Act compliance.

The only documents we store physically for upto a period of 6 years are those documents that fall under the financial legal rules.

John
 
Hi All,

An update to my code, I found that the following code actually deleted all my text files and not just the ones that were 6 months or older, so I've amended and tested the following section of code as follows:

Code before amendment:

=========
BEGIN CODE
=========

'Get the current date - 6 months
dtmDate = DateSerial(Year(Date), Month(Date) - 6, Day(Date))

'If the file found has a ".txt" extension then
If Right(File.Name, 4) = ".txt" Then
'Get the date the file was created
dtmFileDate = Left(File.DateCreated, 10)
'If the created date is equal to or more than 6 months old then
If (DateDiff("d", Date, dtmFileDate) <= dtmDate) Then
'Delete the text file
File.Delete True
End If
End If
=========
END CODE
=========

Code after amendment:

=========
BEGIN CODE
=========
'Get the current date - 6 months
dtmDate = DateSerial(Year(Date), Month(Date) - 6, Day(Date))

'If the file found has a ".txt" extension then
If Right(File.Name, 4) = ".txt" Then
'Get the date the file was created
dtmFileDate = Left(File.DateCreated, 10)
'If the created date is equal to or more than 6 months old then
If dtmFileDate <= dtmDate Then
'Delete the text file
File.Delete True
End If
End If
=========
END CODE
=========

When I tested it in the first instance I only had text files with dates that were older than 6 months, I didn't include text files that had a date less than 6 months! So over the weekend I thought about this and did another test this morning and confirmed what I thought and amended the code accordingly, tested it and confirmed that I am now getting the right results.

John
 
hi all!

i have a similar situation but i need to delete all the files in the folder without any criteria. they are also .txt files.
could someone share a code that i can use ? thanks!
 
To be more specific, below code is which i use to import my .txt files with the criterias given in it. Once i import these files from the given path, as the last operation, i need them to be transferred to another location. (well, this has just flashed on my mind; why delete? let's archive them, isn't better :) ) but still delete them from the folder...
so, any help would be great.. thanks!


Function Load_Attendance_Data()
Dim NextFile, ImportFile, FileCriteria, ctr As Variant
Dim DB_Path, Folder As Variant

' get the DB path
DB_Path = "C:\Documents and Settings\bafkan\Desktop\FTP\"
Folder = ""
FileCriteria = "C:\Documents and Settings\bafkan\Desktop\FTP\" & "VPL*.txt"

' create field with path and filename to import MAKE THIS READ ALL files that start with 'VPL'
NextFile = Dir(FileCriteria)

' Check we have something to import
If NextFile = "" Then
MsgBox "No files to import", , "Error"
Exit Function
End If
ctr = 0

' Import each file that meets the criteria 'VPL*.txt'
While NextFile <> ""

' count files imported
ctr = ctr + 1

' add the path to the returned filename
ImportFile = DB_Path & Folder & NextFile

' Import file into table
DoCmd.TransferText acImport, "VPL", "VPL", ImportFile, False

' get another file if it exists
NextFile = Dir()

Wend

MsgBox ctr & " files imported", , "VPL"

End Function
 
Last edited:

Users who are viewing this thread

Back
Top Bottom