tags:

views:

189

answers:

2

How to check the entered filename in the textbox is correct or not?

Am new to VB 6

In Text Box am entering or selecting the path and filename from local machine or remote machine, once I selected the filename then i want to check the entered file name is correct or not.

I cannot give like textbox = “Selected Path”, because I can select a file from local machine or remote machine but the file name is same.

How can I write a code for entered filename in the textbox is correct or not?

Need VB 6 Help.

A: 

Why do you want to do it like this? It would be much more intuitive and easy-to-use if you use the Common Dialog Control ActiveX to open the file from a local/remote machine.

EDIT: If you want to check whether the file exists, you can use this function:

Function FileExist(file As String) As Boolean
    On Error GoTo Error
    'get the file attributes, and make sure what
    'is being passed isnt a directory
    FileExist = (GetAttr(file) And vbDirectory) = 0
Error:
    'Return False if an error occurs
    FileExist = False
End Function
Kirtan
Not for File exist, I want to check Entered filename is correct or not,
Gopal
Need Exit Function above "Error:" - function as typed always returns False.
MarkJ
A: 

Edited based on comments posted later:

To check the file name if it's valid or not on windows....

Due to differences in Windows architecture, the definition of a valid file name may vary depending upon the component of the operating system and file system you are dealing with.

NTFS file system is the most generous in naming files. The name may be up to 32,768 Unicode characters long. The name can contain trailing periods, trailing spaces, and two files may have names that differ only in case e.g., README.TXT and readme.txt.

On Win32 subsystem, the name can be at most MAX_PATH characters long (defined in windef.h as 260 characters), may not have trailing dots or spaces, and file names are not case sensitive.

DOS and 16-bit Windows applications are still limited to 8 character filename plus 3 characters extension.

Based on the operating system you can apply conditional checks in your VB code to verify a filename as valid or you can come up with a regular expression to verify a file name. However, if you want to be precise then refer to a book or some other sources for more information on the different constraints on file names.

S M Kamran
Following are the forbidden characters in 8 characters filename plus 3 characters extension filenaming scheme... Note all characters are enclosed in single quotes.. ';', '=', '+', '<', '>', '|', '"', '[', ']', '\', '/', '''' And following are the forbidden characters in long filenaming scheme... '<', '>', '|', '"', '\', '/', ':', '*', '?'
S M Kamran