473,387 Members | 1,420 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,387 software developers and data experts.

Does [Sub]Directory Exist?

675 512MB
I want to manage images to use on my form, multiple images per record (row in primary table). I will

put these images in a folder, not as part of a table. There may be 12,000 rows in the table, and 20+

images/row.

I have no problem displaying the pictures. imgDisplayPhoto.Picture = Path & strPicName & ".jpg"

works very well if I hardcode Path. i.e. Form_Load has the statement: Path = "C:\MyProgram\Images\"

I can trap any errors, and display my default picture ("No Image Exists") if none exists.

My users might have the pictures in one-of-three places. 1-With the program; 2-Sub-Directory of the

Program Directory (Preferred); 3-Somewhere else. The user states where the pictures are. This is

straightforward and simple, and not my question.

After the user states where the pictures are located, I want to verify that the path is valid. Also, on

subsequent uses of the program, I need to know if the [Sub-]Directory still exists. It seems that

FolderExists and/or FileExists and/or DriveExists Method would solve my problem.

Access Help has "object.FileExists(filespec)" where "object is Required. Always the name of a

FileSystemObject". What is a FileSystemObject? Access Help is not crystal clear (no surprise), and

http://msdn2.microsoft.com/en-us/library/d6dw7aeh.aspx doesn't help.

I need a statement, function, or method that gives the answer to the question "Does the Folder " &

FolderName & " Exist?", and if the answer is to use FolderExists, how do I use it (give an example)?
Dec 5 '07 #1
5 2579
ADezii
8,834 Expert 8TB
I want to manage images to use on my form, multiple images per record (row in primary table). I will

put these images in a folder, not as part of a table. There may be 12,000 rows in the table, and 20+

images/row.

I have no problem displaying the pictures. imgDisplayPhoto.Picture = Path & strPicName & ".jpg"

works very well if I hardcode Path. i.e. Form_Load has the statement: Path = "C:\MyProgram\Images\"

I can trap any errors, and display my default picture ("No Image Exists") if none exists.

My users might have the pictures in one-of-three places. 1-With the program; 2-Sub-Directory of the

Program Directory (Preferred); 3-Somewhere else. The user states where the pictures are. This is

straightforward and simple, and not my question.

After the user states where the pictures are located, I want to verify that the path is valid. Also, on

subsequent uses of the program, I need to know if the [Sub-]Directory still exists. It seems that

FolderExists and/or FileExists and/or DriveExists Method would solve my problem.

Access Help has "object.FileExists(filespec)" where "object is Required. Always the name of a

FileSystemObject". What is a FileSystemObject? Access Help is not crystal clear (no surprise), and

http://msdn2.microsoft.com/en-us/library/d6dw7aeh.aspx doesn't help.

I need a statement, function, or method that gives the answer to the question "Does the Folder " &

FolderName & " Exist?", and if the answer is to use FolderExists, how do I use it (give an example)?
One way to find out if a Folder exists is the following:
  1. Create a Reference to the Microsoft Scripting Runtime.
  2. Copy and Paste this Public Function to a Standard Code Module:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fDoesPathExist(strPathToFolder As String) As Boolean
    2. Dim fs
    3.  
    4. Set fs = CreateObject("Scripting.FileSystemObject")
    5.  
    6. fDoesPathExist = fs.FolderExists(strPathToFolder)
    7. End Function
  3. Check for the existence of a Folder with similar code to that posted below:
    Expand|Select|Wrap|Line Numbers
    1. 'Pass the Folder's Path (fully qualified) to the Function
    2. If fDoesPathExist("C:\Folder_1\Folder_2\Folder_3") Then
    3.   Debug.Print "Folder does exist"
    4. Else
    5.   Debug.Print "Folder does not exist"
    6. End If
  4. You could also use the Dir$() Function in similar fashion:
    Expand|Select|Wrap|Line Numbers
    1. If Dir$("C:\Windows\System32", vbDirectory) <> "" Then
    2.   Debug.Print "Folder exists"
    3. Else
    4.   Debug.Print "Folder does not exist"
    5. End If
Dec 5 '07 #2
OldBirdman
675 512MB
Beautiful Answer! Thank you very much. I now have a standard function to test for the existance of a Folder or File from a string variable.

One logical place to store my images would be a SubFolder in the folder that contains the program. Is there any way to know the Path of the program from VB code?

Example: Program is C:\Access\ViewPics\ViewPics.mdb pictures would be at C:\Access\ViewPics\Images. I need a function that returns "C:\Access\ViewPics"
Dec 5 '07 #3
ADezii
8,834 Expert 8TB
Beautiful Answer! Thank you very much. I now have a standard function to test for the existance of a Folder or File from a string variable.

One logical place to store my images would be a SubFolder in the folder that contains the program. Is there any way to know the Path of the program from VB code?

Example: Program is C:\Access\ViewPics\ViewPics.mdb pictures would be at C:\Access\ViewPics\Images. I need a function that returns "C:\Access\ViewPics"
  1. CurrentProject.Path will always return the Path to the Active Database as in:
    Expand|Select|Wrap|Line Numbers
    1. ? CurrentProject.Path ==> C:\Access\ViewPics
  2. 'To return the Path to the Images Directory:
    Expand|Select|Wrap|Line Numbers
    1. ? CurrentProject.Path & "\Images\" ==> C:\Access\ViewPics\Images\
Dec 5 '07 #4
OldBirdman
675 512MB
Again, THANK YOU !!!
I spent several hours in MSAccess Help, www.Microsoft. . . , Google, and theScripts Search trying to find this.
Thank you very much again.

OldBirdman
Dec 5 '07 #5
ADezii
8,834 Expert 8TB
Again, THANK YOU !!!
I spent several hours in MSAccess Help, www.Microsoft. . . , Google, and theScripts Search trying to find this.
Thank you very much again.

OldBirdman
You are always welcome.
Dec 6 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: David Krmpotic | last post by:
Hello! I have a simple client/server plugin based architecture. I place all the plugins in \plugins sub-directory on both, server and the client. Each DLL has implemented two interfaces.. on for...
11
by: Leon | last post by:
How do I point a sub-domain to a sub-directory or sub-web of my site using asp.net? I know normally domains are setup to point to the root directory of the web site. However, how can I detect...
9
by: Benny Ng | last post by:
Hi,all, How to let the sub-directory to avoid the authentication control from Root's webconfig? I heard that we can add a new web.config to the sub-directory. And then we can slove the problem....
1
by: olduncleamos | last post by:
Hi all, I am in the process of trying to append a mini app to an existing site in .NET 1.1. The mini app will be added in a sub directory. The existing app uses a custom assembly build a couple...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.