Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Check Path

how do i check the path of an opened file? excel file...
bascially...when i open an excel file...a click button on the spreadsheet would send an email with the attachment (the file itself)...but i do not know the pathname of this file....

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Check Path
I'm using the browse folder API and i want to see if the path that the user selects has a at the end and if it doesn't i want to add it. How would i do that?

VB Code:
Dim strSave As String    strSave = BrowseForFolder(hWnd, "Please select a folder.")    If strSave = "" Then    Else                txtSavePath.Text = strSave & ""        txtSavePath.SaveFile (App.path & "path.ini")    End If

Check Path
G'day All,
I'm using code below to check a path selected by a user.
Can anyone pick holes in it please?
The more critical you are the better.

'GET SOURCE PATH --------------------------------------
inPath = Me.txtPath.Text
'CHECK PATH ----------------------------
If inPath = "" Then
'ToDo: Fix properly!
strTMP = "Select a bloody path, you idiot!"
sknMsg strTMP, 0
Exit Sub
If flgFolder = True Then
If folderExists(inPath) Then
strTMP = "*.txt"
If Dir(inPath & "" & strTMP) = "" Then
strTMP = "No text files in: " & inPath
sknMsg strTMP, 0
Exit Sub
End If
strTMP = "Can't find: " & inPath
End If
If Dir(inPath) = "" Then
strTMP = "Can't find: " & inPath
sknMsg strTMP, 0
Exit Sub
End If
End If
End If

Public Function folderExists(inPath As String) As Boolean
'folder doesn't exist
If Dir(inPath, vbDirectory) = vbNullString Then
folderExists = False
folderExists = True
End If
End Function

Public Function fileExist(inPath As String) As Boolean
If UCase(Dir(inPath)) = UCase(TrimPath(inPath)) Then
fileExist = True
fileExist = False
End If
End Function

Public Function TrimPath(ByVal inPath As String) As String
If Len(inPath) = 0 Then Exit Function
Dim i As Integer
i = InStr(inPath, "")
If i = 0 Then Exit Do
inPath = Right(inPath, Len(inPath) - i)
TrimPath = inPath
End Function

Check For Valid Path
I am using a registry entry make the save path for a file "sticky" between program executions. However, when the user uses a removable drive and the registry gets set to that path, the app will crash when it tries to open the file at that path. (i.e., the user saves to a USB drive at f: emp, then pulls the drive out. Next time the program is run it tries to save to path f: emp, which doesn't exist, and the program blows up).

I guess this could be fixed with error handling, but is there an easy way to programatically check if the path is valid BEFORE trying to open the file?


Check Network Path
I'm looking for an easy way to check whether there's a connection to another computer on the network.

My idea is to use:

Shell("net use > file.txt")
<search file for computer: \networkadress>
Net Use shows me all current network connections. But somehow this doesn't work out of my program - there's no file created and nothing written. When using this command over command-box the result is correct.

Does anyone see the mistake in my Shell-command?
Or do you have an idea how i can check the connection to a computer on the network?

Thanks, Jeannette

Check Path Problem
Hello I have problem.

I need check that path Is here Or Not.

I try doing this, [wrong code], but what wrong...?

Begin: use
checkdir(0) = "D:\_MB813_"
checkdir(1) = "D:\_MB"

First, use
For i = 0 To UBound(checkdir)
If checkdir(i) that path Is here, keep it
Next i

If checkdir(0) Is HERE And checkdir(1) Is HERE ,
FINAL_PATH = checkdir(1)

If checkdir(0) Is NOTHERE And checkdir(1) Is HERE ,
FINAL_PATH = checkdir(0)

If checkdir(0) Is NOTHERE And checkdir(1) Is NOTHERE ,
FINAL_PATH = appdrive & ":"

Dir1.Path = FINAL_PATH


Private Sub Command1_Click()

Dim appdrive As String
Dim checkdir() As String
Dim i As Integer

appdrive = Left$(App.Path, 1)

checkdir(0) = MakePath(appdrive & ":\_MB")
checkdir(1) = MakePath(appdrive & ":\_MB" & getdaytime(1) & getdaytime(2) & "_" & "")

For i = 0 To UBound(checkdir)

If Not Dir$(a, vbDirectory) = vbNullString Then
'MsgBox (a) 'folder here
Exit For
Next i
End If

End Sub


Private Function MakePath(sPath As String) As String
MakePath = sPath
If Right$(MakePath, 1) <> "" Then MakePath = MakePath & ""
End Function


Function getdaytime()

Dim Todays_date As Date
Dim mm2, dd2, yyyy2, hour2, min2, sec2 As String

Todays_date = Now
mm2 = (Format(Todays_date, "MM"))
dd2 = (Format(Todays_date, "DD"))
yyyy2 = (Format(Todays_date, "YYYY"))

hour2 = Hour(Time)
min2 = Minute(Time)
sec2 = Second(Time)

If (hour2 < 10) Then hour2 = "0" & hour2
If (min2 < 10) Then min2 = "0" & min2
If (sec2 < 10) Then sec2 = "0" & sec2

getdaytime = Array(yyyy2, mm2, dd2, hour2, min2, sec2)

End Function


How Can I Check If A Path Is Valid?
Hi, When i ask a user for a specific program path in a input box,
how can i then check if that path exists?
Is there a function that check's if file's exist on the hardrive?

I would really apriciate any help on this.


Check If Any Sub Dir Exist In App.Path If So Then
Ok what I am wanting to do is Check if ANY Sub Directory exist in the main app path.

On Form Load
If the return is False and no Sub Dir exist then I want to create a Directory based on Input from the user( user names Dir) (if Possible only Numbers allowed for the DIR Name)

If return is true and Dir or Directories Exist Then I want to load all the Sub Directories found to be loaded into a ComboBox


Check If Path Exists
how to i make it so vb6 check if a folder/path exits like "c:/Program Files/BlaBla/"

Check Server Path
VB Code:
Dim serverFolder = "//sapt01/in/"      If Dir(serverFolder, vbDirectory) = "" ThenMsgBox ("Dont have access to SAP server!"), vbCriticalelse'Do transfer  

This code is for checking directory is exist or not.
i tried to use the code to check the server path(as above) but failed.
so how to check the server path in proper way?

Check Path && Filename?
what code would i use to check if a path & filename exist?

Check If Path Exists Using Fso
I have a string variable that holds a directory path...

I am copying a file to this path, but need to check to make sure the path exists first: the path looks like this:


Do I have to check all directories in order to create this path if
it doesn't exist, such as

Check(C:Programming) if doesn't exist, create it

Now check (C:Programmingmydirectory) if it doesn't exist, then create it.

Or is there a way I can just give it the one path:

C:ProgrammingMyDirectory and if it doesn't exist, it will automatically create the other folders underneath if they don't exist????????

How Do You Check File Path Name
I am trying to check a file path name that a user inputs.

for example if a user types in a file path name "sdfkhlefksdjflkjdsl",
how would i check to see if that is actually a vaild path?

Best Way To Check If Path Is Writable...
Hi everyone...

I had no idea how to search for my query, so I thought it would be quicker to start a new post.

Not using the FSO, what is the best way to check to see if a path/drive is writable? It would be useful for checking cd-rom drives, write protected diskettes, or network paths where permissions are denied...


Edited by - D-Race on 9/28/2005 5:45:34 AM

Auto Check Databse Path
hi, how to check if a network database path is working or is valid? or if there is error in connecting to a database that found on a server.

Check Network Path Exists
Hi all,

I have searched but can't find an answer to this.

If I have a string containing a file path. eg "R:AdministrationTimekeeping est.xls" How do I check that the path exists?

If the computer running the app is not connected to the network, and hence the path doesn't exist, then using this code

Public Function FileExists(strFilePath As String) As Boolean
FileExists = False 'Assume the worst!
'Make sure a filename was passed!
If Len(strFilePath) > 0 Then
'Check to see if the file exists!
If Len(Dir$(strFilePath)) > 0 Then
'The file exists!
FileExists = True
End If
End If
End Function

If Len(Dir$(strFilePath)) > 0 Then

still creates an error "bad file name or number"

Can someone suggest a way of finding out whether or not a path exists?

How Do I Check A Network Path Using DIR Function

I am using the DIR function to check if the path exists. I am reading the path from an INI file. If I specify the local system path (C:ProjectsMyDir)...then it returns MyDir which is expected. But when I specify a network Path (\ServerNameMyDir) then it gives me Error 52: Bad File Name.

What I did was share the file MyDir and then tried to access it? It was not working and was giving the error. But when I shared the parent folder i.e. Projects and gave the path (\ServerNameProjectsMyDir) it gave me the correct result. i.e MyDir.

I want to know why is this happening as we can access the same path from our windows (Start --> Run ). Is there some technical limitations to the DIR Function in such a case.

Pls help


Check If .dll Exists (non-path Specific)
I'm wondering if its possible to detect if a DLL is registered, or in a directory where it would be found (System, System32, Windows, etc.)


Fast Network Path Check
I need to check if a file is available over a LAN. I am using the following code:

VB Code:
If Dir(tweak.master_database_path & "user.mdb") <> "" Then   TreeView1.nodes.Add , , "MDB", "Master Database", "folder"   TreeView1.nodes.Add "MDB", tvwChild, "MDB,Blank", "Blank"Else   TreeView1.nodes.Add , , "MDB", "Master Database", "critical"End If

but there is a big delay if the database file is missing (e.g no network connection)

Is there a faster way of doing this?


Ho W Do I Check If A Field Contains A Valid Dir. Path
I have a text field that is used to access folders. I want to make sure that when I click the OK button, if an invalid dir. path was entered it will detect if that file path is valid or not.

File Path Validation Check
Hi everyone,

How do I check that a file path is valid and existing?
(So that the user will not have to see a run-time error generated, in case that the specific file path is invalid / non-existant.)

And if a file path is found to be invalid and non-existant, the program should allow the user to browse and select the specific file desired.
(Still trying to work this out with Common Dialog control)

Any ideas / suggestions on how I should go about doing this? I've been trying to think this out for almost a day now.

Many thanks in advance.

Check If String Path Is A File Or Folder
I have a source path field for one of my apps. Depending on the content, I want to manipulate the string differently.

if i have "C: est" then I want to add "*.*" to the end
if I have "C: est" then i want to add "*.*" to the end

if I have "C: est*.*" then i want to leave it alone
if I have "C: est*.txt" then I want to leave it alone
if I have "C: estw?d.txt" then I want to leave it alone
if I have "C: estlah.txt" then I want to leave it alone

Whats the best way to check for all those conditions?

I've tried checking if the path file exist, but that would only apply to the last row.

I've tried checking if the path didn't have a "*" in it, but that wouldn't work if an actual file or ? existed

I've tried checking if the path is a file or a directory, but I'm not really sure how to do that. Still wouldn't give expected results for wildcards.

So I'm stuck trying to figure out how to manipulate and handle all possible entries. I have attempted to catch it during creation, which works fine, but if there was a manual file edit or something where they forgot the proper characters, I want to be extra foolproof.

Any ideas?

Check The .exe File Running Directory Path
Hi, all
i have written a simple vb project code, now i need to make the program more flexible. actualluy, i need to open a .ini file and read the data inside the file each time to run the whole program. In my own pc, i just hard-code the path of the .ini file in the project code. So it wroks well .

but now if i send the project .exe file to the other user, it won't work, because i don't know the path name of the .ini file in its pc.

Because i always send the .ini file and the project .exe file together. and ask the user put them together in the same directory. So now i want to know is there a way to check out the full directory name of the .exe file , when it is running. So i can know the path name of the .ini file.

can you all help me? thanks a lot!!!

Check If User Typed A Valid Path
hey all
What can i do to find out if the user typed a valid path name?
In my app, the user is choosing (browsing) an *.exe file(With dirlist and filelist), that's the 1st way.
the user can choose another way to select an *.exe file, he can type
the file's path directly to a textbox, but here comes my prob:
if the user typed: "C:/sdfsadf/asdfasdf.exe" or just "asdf", how can i check if he typed a valid path? (Will check if file exist will do the work?)
tnx for replies

Check Network Path Validity/existence
I wonder to create a function that receive the string of path exp: "\STEVEN" or "C:Program Files"...

then the function will check the existence or is it the path valid and available or not...

ty for reply^^

Urgent!Help! How To Check Network Path Exist?
I wan to write a function that receive the network path as string....
exp: \stevenMy documents

Got any function or code can check the network path exist or not?

ty for reply^^

[solved]How To Check The Directory(or Path) Of The Program?
In my program, I use ADO data control to access my .mdb file.
Since, I don't want to hard-code the location of the .mdb file in the connection string ( that is, if the program and the .mdb are moved to somewhere else, the program would face an error).
The program and the .mdb file are located at the same directory.
Therefore, is there any way to check where the path of the program at startup, then put the path into the connection string?
Thanks for any suggestion!

Edited by - seleven on 10/28/2003 4:28:25 PM

Check If Given Path Exists In Lokal Network
I need to check if a given pathname like '\PcNamepath' exists in a lokal network ( 3 PCs with Win Me connected together, no server ) How can I do that in VB 6.0 Is there any API which can be used ?

Jonny Poet

How Can I Check The Installation Path Of My Users' Browser ?
Is there a way to determine the installation path of my user's browser (IE or NetScape) ?
Pls enlighten. Lots of thanks !!

VBscript To Check Folder && Send Email If File Exists Along With Path
I need a script which scans through folders and send email if file exists in particular folder, can someone help please.

Many Thanks in advance

Checkbox..... Check Check Check Check Check...oops Stack Error
I have three check boxes one on each of my SSTab tabs. If one is checked the other two needs to be unchecked.... and so on. I use this to determine which is the default website. is the code I used....

Select Case Index
Case 0
chkDefaultWebsite(1).Value = vbUnchecked
chkDefaultWebsite(2).Value = vbUnchecked
' Case 1
chkDefaultWebsite(0).Value = vbUnchecked
chkDefaultWebsite(2).Value = vbUnchecked
Case 2
chkDefaultWebsite(0).Value = vbUnchecked
chkDefaultWebsite(1).Value = vbUnchecked
End Select

Simple enough right? Well the first time I click on the check box, my box isn't checked but my others are when I click again it checks it..... so I did this....

Select Case Index
Case 0
chkDefaultWebsite(0).Value = vbChecked
chkDefaultWebsite(1).Value = vbUnchecked
chkDefaultWebsite(2).Value = vbUnchecked
Case 1
chkDefaultWebsite(0).Value = vbUnchecked
chkDefaultWebsite(1).Value = vbChecked
chkDefaultWebsite(2).Value = vbUnchecked
Case 2
chkDefaultWebsite(0).Value = vbUnchecked
chkDefaultWebsite(1).Value = vbUnchecked
chkDefaultWebsite(2).Value = vbChecked
End Select

And of course I get a stack error of endless days err...I mean looping on the check box.....

How can I get that to check the first time I click on it and also uncheck the others ???

Thanks again !

How Do You Check If The File Path Is Existing Or Not Using ASP And In Client Side Not Server Side?
I'd like to know if a user entered a Path for a File the Path is existing or not and I'm using ASP not VB. In VB it is possible but in ASP it does not work. This is the code I used:

' Reference MS Scripting Runtime
Public Function FileExists(strFullPath As String) As Boolean
Dim oFile As New Scripting.FileSystemObject
FileExists = oFile.FileExists(strFullPath)
End Function

Note: This will run in VB but not in ASP, is there a code that I can use in ASP?

Path/File Access Error Grrr. It There A Way To Check To See If The File Is In Use?
Cause once I get this error a can't "On Error" around it.

Check For A "" At The End Of A Path
What's the best (most efficient) way to check for a "" at the end of a path?

This is what I'm using right now, would a Mid() be better here?

' Set a path for help file
If Right$(App.Path, 1) = "" Then
HelpFilePath = App.Path & "myhelp.chm"
HelpFilePath = App.Path & "" & "myhelp.chm"
End If

Get A Network Files Local Path From Its UNC Or Mapped Drive Path
After a user browses for a file, if it is a network file I want to get the path that is local to that networked computer. For example if I have a mapped drive named "N:" which maps "\ServerShared" which is "C:Shared" on the server, if a user browses for a file and selectes "N:MyFile.txt" or "\ServerSharedMyFile.txt" I want to get the path that is local to Server, which is "C:SharedMyFile.txt". I have been searching the forum with no luck but if it is out there and you could please point me in the right direction... Thanks!

Mapping Windows System Folder To Application Path(EXE Path)
Dear all,

My problem is this :

I am using an ocx's for flex grid & Image edit for displaying data & images.

I want to keep my EXE file & the supporting files in CD, so that anyone can run this application from CD.

I don't want to do installation package & also not to register the ocx files. Instead of this I'll keep my supporting files along with EXE in CD.

I want to map system folder to my app.path (in CD), so that my application will run taking supporting files in CD rather than windows system folder.

Here I'm stuck.

By doing this I can avoid regestering OCX or developing package.

Please help me to solve this problem.


Dir(path && Filename) Error If Path Is To Cdrom?
i always get an error in my code

Dir(path & filename)
if path is a drive letter for cd rom...
how can i avoid this error?

VB RunTime 76 Invalid Path Name; Path Not Found. Please Help
I am writing an application that the user inputs three things. 1. Path To List 2. Path To Save Text File 3. Name of text file. The user inputs the Path To List and presses the List Files button. Then the user inputs the Path to save the file, and 3rd the name of the file. Then they press transfer which moves the list from the FileListBox to the ListBox and then writes a text file of the list. If the user inputs a nonexisting directory they will get a RunTime 76 error invalid path name; path not found. I was wondering if there was a way to test to see if a directory path is valid. Please Help! any help is extremley appreciated.

Path Not Found Error, But Path Exists
I am getting a path not found error on the highlighted line, but the thing is, the path is found. i tried to debug and the information seems right.

VB Code:
Private Sub cmdSaveFile_Click()    m_strProjectsDirectory = "Projects"    m_strBackupDirectory = "Backups"    m_strSaveProjectFileName = txtFileName.Text    m_strSDPROJFileName = m_strSaveProjectFileName & ".sdproj"    m_strFileNameLocation = App.Path & "" & m_strProjectsDirectory & "" & m_strSDPROJFileName        If Len(Dir$(App.Path & "" & m_strProjectsDirectory & "", vbDirectory)) > 0 Then        'do nothing because the Projects directory exists    Else        MkDir (App.Path & "" & m_strProjectsDirectory & "")    End If        If m_strSaveProjectFileName = vbNullString Then        MsgBox "You must input a filename!", vbExclamation, "Error Encountered."        Exit Sub    ElseIf LCase(Right$(txtFileName.Text, 7)) = ".sdproj" Then        MsgBox "Input your file name, excluding the file extension.", vbInformation, "Error Encountered."        Exit Sub    End If        If FileExists(m_strFileNameLocation) Then        m_intMsgBoxAnswer = MsgBox("The file name that you have specified is already in use." & vbNewLine & _                                   "Would you like to overwrite this file?", vbExclamation + vbYesNo, "File Name in Use.")        If m_intMsgBoxAnswer = vbNo Then            MsgBox "The file has not been overwritten" & vbNewLine & _                   "and has not been saved anywhere.", vbInformation, "File Not Overwritten."            Exit Sub        Else 'If vbYes Then            If Len(Dir$(App.Path & "" & m_strBackupDirectory & "", vbDirectory)) > 0 Then                'do nothing because the backup directory exists            Else                MkDir (App.Path & "" & m_strBackupDirectory & "")            End If                    'copy the file to the backup directory, date and time stamp it so as to prevent file copy            'problems            [hl]FileCopy m_strFileNameLocation, App.Path & "" & m_strBackupDirectory & "" & Date & Time & m_strSDPROJFileName[/hl]                    'delete the file from the original directory            Kill m_strFileNameLocation                    'rewrite the file            WriteProjectFile                        'inform the end user            MsgBox "The file has been overwritten as requested. Please note that" & vbNewLine & _                   "the file was also backed up for you and placed within the" & vbNewLine & _                   "backup directory." & vbNewLine & vbNewLine & _                   "The location of the backup directory is:" & vbNewLine & _                   App.Path & "" & m_strBackupDirectory & "" & vbNewLine & vbNewLine & _                   "The name of the backed up project file is:" & vbNewLine & _                   Date & Time & m_strSDPROJFileName, vbInformation, "File Overwritten."        End If    Else 'file name not in use        WriteProjectFile    End If        Unload MeEnd Sub

Convert UNC Path To Local Drive And Path
I thought there was a way to do this but I can't remember it. Ho can you convert a UNC path back to a local drive and path (mapped or local). I believe there was an API but I can't find it.

ex. \serverdevelopment converts to Z:Development

Find The Path, Enter Path Into String
What I want to do is search for a file on a drive and have
the path name entered into a string... for example pth$

Print #2, "C:"
Print #2, "CD"
Print #2, "CD Program*" < Prob 1
Print #2, "CD America's*" < Prob 1
Print #2, "CD System"
Print #2, "CD Save" < Prob 2
Print #2, "CD save" < Prob 2
Print #2, "DIR /A /O:D > C:" & ID$ & "save.LOG"

Also I have the following problems with the code above.
1. There are two directory's that are named "CD America's"
The problem im having is I canot use spaces and have to use a astrix.
2. Case sensitive for going down directories.


File Path Withouth Application Path
Hi all,

my program uses some sub directories to store data in it. The user can select files through a common dialog (file open) control.

What i need is the location of the file WITHOUT the application path/folder. So something like

app.path = c: estapplication1

filelocation = c: estapplication1files est1.txt

result (what i need) should be then = files est1.txt

Any ideas about this one?



How To Set The Current Drive And Path To A Network Path?
Hi everybody,

In my client's office, there is a Windows 2000 Advanced Server computer and several Windows 98 workstations connected to it. From a workstation computer I want to set the current drive and path to "\ServerServer eMarket". Is that possible without mapping the network drive?

How Can I Conver A Short Dos Path To Windows Path?
How can I conver one of those shortened paths like msdos paths to windows paths (the actual file is not shortened)
(like when you have progra~1 instead of program files)

Convert A Long Path Name To A Short Path Name (8+3)

Does some one could tell me how could i convert a long path name to a short path name (8+3)

For exemple :



Thank you for your help.....

Help With Path Of File / Shell Program Path
Currently I am using the shell command to open an application called Kodakprv.Exe. Their are going to be multiple users for my application and of course the Kodakprv.Exe is in a different directory on each PC. Is their a way to find the directory that the kodakprv.Exe is in and then use that as Path in the shell command to open Kodakprv.Exe. Any help would be greatly appreciated.

Here is the code I have now


sAppName = Trim(strImageName) & " - Imaging Preview"
intRet = Shell("C:Program FilesWindows NTAccessoriesImageVuekodakprv.exe \lightfootd-drivewebsecurescanimages" & strImageName, vbNormalNoFocus)

TEMP Path? System Folder Path?

i need to extract a temporary file onto my clients computers, and i want this file to go to the windows temporary directory, (e.g. c:windows emp or c:winnt emp)

is there a way to find this temp directory on the clients machine and then set that into a string to use? because some operating systems have different paths to their temp directory, my script must be dynamic


Edited by - Ahmz_055 on 12/11/2004 4:59:01 PM

How To Obtain Relative Path From Absolute Path?

How do I obtain the relative path (e.g. "....Test.tmp" ) from the absolute path ( "C:Test.tmp" ) with respect to a directory (e.g. C:Temp2Dir2 )? This should work irrespective of where the file Test.tmp is stored.
Do you have any sample code which could help me do this?

Any help would be greatly appreciated.

Thanks and Regards,

Application Path Or File Path I Am Not Sure
I have a very small exe that is written in vb6.0 It is so small it doesn't require any setup program to run it.

So here is my question. When the user moves the exe to a folder on load I want to display the location of the exe to the user if they request it and to load the proper help files if they have moved them along with the exe.

Does anyone have any sample code of how to do this. I am sure it could be done with an api call, but wouldn't know where to start.

Any help as always is greatly appreciated.


Path Location Problem Dir.path
I have problem here.. i have textbox that store path location. It show in the textbox as C:\ . How I can show in the textbox as C: ?

Dir1.Path = Text1.Text

Copyright 2005-08, All rights reserved