|
-
Oct 30th, 2009, 05:52 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] How to check if a named file exists on a machine
I want my program to start by checking that a number of files, of known location and extension type(s) is present on the PC before going on to run the app. These files will be the associated dependency files, plus certain others which previous instances of the program may have generated. Their extensions could be anything, including .dll, .ocx., .exe, .txt, .doc etc.
If a listed file is not present, I will use a message box to inform the user. My thought is to incorporate this code at the form load event. The message(s) will prompt the user to load the necessary files.
The following code seems to work so far. It requires placing a rich text box on the form (which can be small, and non-visible) and trying to load the desired file into it. If the file is not present, the On Error process brings up the Message Box :-
Dim PATH as String
PATH = "C:\Windows\System\abcde.xyz"
On Error GoTo Line10
RichTextBox1.LoadFile PATH, rtfText
GoTo Line20
Line10: MsgBox "FILE OPEN ERROR. CHECK PATH " & PATH
Line20:
(progam then continues to check for next file etc. etc. ........)
Is there please a more elegant way to achieve this, and one which will work with absolutely any extension type? I have not yet found an extension type which the above code does not deal with, but maybe there will be a few?
camoore
Wales, UK
Last edited by camoore; Oct 30th, 2009 at 05:56 AM.
Reason: missed out " " at second line of code
-
Oct 30th, 2009, 05:56 AM
#2
Re: How to check if a named file exists on a machine
See if this helps you 
http://www.vbforums.com/showthread.php?t=349990
Also one more way which is not mentioned in that thread...
vb Code:
Function DoesExist(FileName As String) As Boolean On Error GoTo Error '~~> Get the "FileName" attributes, and make sure what '~~> "FileName" isnt a directory DoesExist = (GetAttr(FileName) And vbDirectory) = 0 Error: '~~> Return False if an error occurs DoesExist = False End Function
Last edited by Siddharth Rout; Oct 30th, 2009 at 06:00 AM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 30th, 2009, 06:17 AM
#3
Thread Starter
Hyperactive Member
Re: How to check if a named file exists on a machine
Thank you very much, Koolsid, for your such rapid reply and for the pointer. I was sure there must be a more elegant method than mine. However, I did find yet another use for the rich text box. This seems a most useful device about which there is very little mention in all my VB textbooks.
I will mark the thread closed.
camoore
Wales, UK
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|