473,221 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

determine whether a path is a directory or a file

does any one here know of a good way to to determine whether or not a
given path is a directory (e.g., "c:\mydir") or a file (e.g., "c:\mydir
\myfile.txt")?

i started attacking this problem by using filesystemobject to check
whether or not a directory existed for the path. if so, it was a
directory path. if not, i checked to see if a file existed for it. if
so, it was a file path. this code is shown below:

''''''''''''''''''''''''''''''''''''
function GetPathType(byval sPath)
const INVALID = 0
const DIRECTORY = 1
const FILE = 2

dim iResult : iResult = INVALID

dim fso : set fso = CreateObject("Scripting.FileSystemObject")

if fso.FolderExists(sPath) then
iResult = DIRECTORY
elseif fso.FileExists(sPath) then
iResult = FILE
end if

set fso = nothing

GetPathType = iResult
end function
''''''''''''''''''''''''''''''''''''

but, what if i need to determine a path type regardless of whether or
not the directory or file currently exists?

any ideas out there?

thanks in advance

Feb 1 '07 #1
1 2533

"topramen" <ah***@oneirasoft.comwrote in message
news:11********************@h3g2000cwc.googlegroup s.com...
does any one here know of a good way to to determine whether or not a
given path is a directory (e.g., "c:\mydir") or a file (e.g., "c:\mydir
\myfile.txt")?

i started attacking this problem by using filesystemobject to check
whether or not a directory existed for the path. if so, it was a
directory path. if not, i checked to see if a file existed for it. if
so, it was a file path. this code is shown below:

''''''''''''''''''''''''''''''''''''
function GetPathType(byval sPath)
const INVALID = 0
const DIRECTORY = 1
const FILE = 2

dim iResult : iResult = INVALID

dim fso : set fso = CreateObject("Scripting.FileSystemObject")

if fso.FolderExists(sPath) then
iResult = DIRECTORY
elseif fso.FileExists(sPath) then
iResult = FILE
end if

set fso = nothing

GetPathType = iResult
end function
''''''''''''''''''''''''''''''''''''

but, what if i need to determine a path type regardless of whether or
not the directory or file currently exists?

any ideas out there?
Not strictly possible.

A file with no extension would as a string look identical to a folder path.
Also a dot in a folder name is not illegal.

However it's reasonable to assume the file will have a short extension
hence:-

Function ProbablyAFile(sPath)
Dim rgx : Set rgx = New RegExp
rgx.Pattern = "\.[^\\]{,5}$"
ProbablyAFile = rgx.Test(sPath)
End Function
Feb 1 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dfenestr8 | last post by:
os.listdir("path") returns the names of all the items in a directory ok, but I need to know whether the item is a file or a directory. Can anybody tell me how this could be done?
5
by: bart plessers | last post by:
Hello, Currently I am developping a internet "directory browser" My page 'default.asp' has following entries: CurrentPATH = Request("MyLink") Set oFSO =...
13
by: could ildg | last post by:
I want to check if a folder named "foldername" is empty. I use os.listdir(foldername)== to do this, but it will be very slow if the folder has a lot of sub-files. Is there any efficient ways to do...
1
by: Tim Marsden | last post by:
HI If I have 2 strings each containing a Path string, but in different formats. e.g. 1. "D:\My Folder\My Sub Folder\A.txt" and 2. "\\ComputerA\Share B\A.txt" Now do I compare these to...
3
by: KSC | last post by:
Hello, Is there a way to programmatically determine if a directory is shared and if so, what the sharename is? It seems a simple question, but I have been searching and not found the...
28
by: Tim Daneliuk | last post by:
I have a program wherein I want one behavior when a file is set as executable and a different behavior if it is not. Is there a simple way to determine whether a given named file is executable...
2
by: Markus | last post by:
Hello Is it possible to determine the PHP path to the FTP base directory? ftp_pwd($conn_id) returns '/', while I need something like '/data/users/domain.com/'. I used a construct such as: ...
0
by: grejon04 | last post by:
I'm trying to write a script that will look into a directory, and check each entity to see if it is a directory or a file. (Borland CodeGear RAD Studio) Here's what I have so far. #include...
6
by: lawpoop | last post by:
I'm working on a PHP site and I have my database password file behind the server root directory. I can reference the password file by include("../ database_password.inc.php"), but I would like...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.