|
-
Jun 7th, 2006, 06:19 AM
#1
Thread Starter
New Member
FileName Validation help plz
All,
I have to check a dir for new arrivals of files. I need to check a certain format and make sure the filenames follows that format. How can I validate all the filenames so that thier name's format is correct? Also I have to do this every 1 hour and to process the new files that just arrived to the same dir, the one I did not process?
Many thanks
-
Jun 7th, 2006, 06:24 AM
#2
PowerPoster
Re: FileName Validation help plz
The Dir() command would be your best bet, I think...others might have better options but I'll explain mine anyway
if you do d=dir("c:\*.*") then d becomes the filename of the first file in this folder...if you then do MORE "d=dir()" (notice that I haven't included the folder location this time) it will return the next matching filename (and *.* ensures it matches all files)
If you were to set up a function that basically loaded all names into an array, you could then check the array for new names or check names for valid formats and such :-)
BTW, if you put the d=dir() in a 'do/loop while d<>""' then it would repeat until no more files were found...if dir() returns a null ("") value then that means there's no more files to get
-
Jun 7th, 2006, 09:46 AM
#3
Re: FileName Validation help plz
I'm with smUX.
Besides this when you want to check whether a file name is in particular format or not then use the LIKE keyword.
VB Code:
m = Dir("C:\Test\*.*")
If Not UCase(m) Like "A##.DOC" Then 'filters out files like A001.doc, A56.doc etc.
'invalid file name. etc.
MsgBox "Invalid file name" & m
Else
'whatever
End If
Pradeep
-
Jun 7th, 2006, 08:07 PM
#4
Thread Starter
New Member
Re: FileName Validation help plz
Thanks but I can't write any thing. This is the code. What am I missing?
'Create the file
Dim oFile As System.IO.File
Dim oWrite As System.IO.StreamWriter
'Write to the file
oWrite.WriteLine("Write a line to the file")
oWrite.WriteLine(m) 'Write a blank line to the file
-
Jun 7th, 2006, 08:11 PM
#5
Re: FileName Validation help plz
 Originally Posted by bengalliboy
What am I missing?
Reading this forum name, that's missing. Try VB.Net Forum Here
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|