Results 1 to 5 of 5

Thread: FileName Validation help plz

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    3

    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

  2. #2
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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:
    1. m = Dir("C:\Test\*.*")
    2. If Not UCase(m) Like "A##.DOC" Then    'filters out files like A001.doc, A56.doc etc.
    3.     'invalid file name. etc.
    4.     MsgBox "Invalid file name" & m
    5. Else
    6.     'whatever
    7. End If

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    3

    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

  5. #5
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: FileName Validation help plz

    Quote 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
  •  



Click Here to Expand Forum to Full Width