|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
||||
|
||||
|
Hi, Is there an easy way in VB6 to check to see if a file exists?
It seems daft to have to try and open it and then trap and error. All I want to do is check to see it a file exists and if it does then I want to copy it to another folder. I can't get it to work. All the ON ERROR GOTO label stuff really makes a mess of the structure of my program. Is there a way like in C :- handle = fopen(.... etc etc) and then handle is NULL if the file doesn't exist? That seems a more elegant way of doing it. Thanks |
|
#2
|
|||
|
|||
|
May be this helps....
Code:
'Assume That The File Is At "C:\What\File.txt"
If Dir("C\What\File.txt") <>"" Then
FileCopy "C:\What\File.txt", "C:\Where\File.txt"
Else
MsgBox "File Does Not Exist!"
End If
__________________
I May Have Misinterpret U'r Post Correct Me If I Am Wrong......// Enjoy Coding........................../// zak2zak |
|
#3
|
||||
|
||||
|
Re: File Exist In VB?
Quote:
Yes. Thank you VERY much. That has done the trick ![]() |
|
#4
|
|||
|
|||
|
In anther way:
if Len(dir(C\What\File.txt") >0 Then FileCopy "C:\What\File.txt", "C:\Where\File.txt" Else MsgBox "File Does Not Exist!" End If or Use Ms srcipt object... |
|
#5
|
|||
|
|||
|
What is the syntax if I want to check for file in same directory as executable?
For example, I have an executable that relys on an INI file for info. The INI file should be located in the same location as the EXE file. So I need to check to see if INI file is there. This doesn't seem to work: If Dir("File.ini") <>"" Then MsgBox "File Exists!" Else MsgBox "File Does Not Exist!" End If |
|
#6
|
|||
|
|||
|
May Be This Helps..
Code:
If Dir(App.Path & "\File.ini") <>"" Then MsgBox "File Exists!" 'Statement here Else MsgBox "File Does Not Exist!" End If |
|
#7
|
||||
|
||||
|
FileSystemObject Solution
If you are using the FileSystemObject then
FileSystemObject.FileExists(filePath) Returns True or False. filePath can by absolute or relative. |
|
#8
|
|||
|
|||
|
Re: Check INI In Same Dir
Quote:
This did the trick. Thanks a bunch. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > An easy way to check to see if a file exists in VB6? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|