|
-
Feb 9th, 2003, 09:20 AM
#1
Thread Starter
Addicted Member
File Exist
Ok in my program I have a log file that gets displayed in list box when you click a command button but if the log file isnt there it has error file not found so what I want to do is find if the log file exits or not and if it does exist it gets displayed in list box but if its not in the directory of the program then in the lasit box it says No file found... So code/help/ideas anything for this would be GREATLY appreciated
Thanks For The Help Guys 
-
Feb 9th, 2003, 09:26 AM
#2
Frenzied Member
Code:
Function FileExists(filename as str) as Boolean
FileExists = (Dir(filename) > "")
End Function
Usage:
Code:
If FileExists("C:\myfile.log") then
' open the file
Else
msgbox "File not Found", VbOkOnly
End if
-
Feb 9th, 2003, 10:53 AM
#3
Thread Starter
Addicted Member
Originally posted by jim mcnamara
Code:
Function FileExists(filename as str) as Boolean
FileExists = (Dir(filename) > "")
End Function
Usage:
Code:
If FileExists("C:\myfile.log") then
' open the file
Else
msgbox "File not Found", VbOkOnly
End if
That seems pretty sweet but with the code above:
VB Code:
Function FileExists(filename as str) as Boolean
FileExists = (Dir(filename) > "")
End Function
that gives me an error saying"Compile error:
User-defined type not defined"
Whats wrong with it and how do I fix it??? Well thanks and all help is very much welcome
Thanks For The Help Guys 
-
Feb 9th, 2003, 11:12 AM
#4
Thread Starter
Addicted Member
Could someone please state what the problem in this is? Thanks for your time and help in avance
Thanks For The Help Guys 
-
Feb 9th, 2003, 11:19 AM
#5
Stuck in the 80s
VB Code:
Function FileExists(filename As [b]String[/b]) As Boolean
FileExists = (Dir(filename) > "")
End Function
-
Feb 9th, 2003, 11:25 AM
#6
Thread Starter
Addicted Member
Ok well thanks man but jim had:
If FileExists("C:\myfile.log") then
' open the file
Else
msgbox "File not Found", VbOkOnly
End if
But I dont want it C:\myfile.log I want it LogFile which is located in the programs directory? Thanks for the help everyone
Thanks For The Help Guys 
-
Feb 9th, 2003, 11:41 AM
#7
VB Code:
If FileExists(App.Path & "\myfile.log") Then '...
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Apr 4th, 2003, 10:05 AM
#8
Member
WHAT if
hey, what if you just want to check if there are any file's with a certain extension ?? ( .txt ?) or any file that starts with a certain character ( as001.txt )
Thanks everyone
-
Apr 4th, 2003, 10:15 AM
#9
You should just be able to use the '*' as a wildcard...
VB Code:
If FileExists(App.Path & "\a*.txt") Then '...
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Apr 4th, 2003, 10:22 AM
#10
-
Apr 4th, 2003, 04:55 PM
#11
Member
app.path
hey , thanks for the help btw
one more question how can i change the path of the APP.PATH ?
Thanks
Paolo
-
Apr 4th, 2003, 07:50 PM
#12
PowerPoster
Well
App.Path is a variable within VB that hold the current directory path to your app. You want to change it? Install your app someplace else. If you need to set the path, just use something like :
VB Code:
If FileExists("c:\MYPATH\a*.txt") Then '...
App.Path is not necessary...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Apr 4th, 2003, 11:52 PM
#13
Member
hey thanks, dont know why i didnt think of that...i am such a newbie...but anyway.. i have another question ...how can i put that path into a string....
i would like to open that file ?
thanks
-
Apr 5th, 2003, 05:38 PM
#14
PowerPoster
Well
VB Code:
Dim STRFILENAME as String
STRFILENAME = "C:\TEST.TXT"
If FileExistsSTRFILENAME ) Then '...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Apr 5th, 2003, 06:08 PM
#15
Member
sorry
thanks , but this is what i really want to do,and i apologize for not explaining it right...
1. i need to make sure that a file exist on a folder with a .txt extension.
2. after verifying that the fileexist, i would like to open it
3. last is to append some data to that text file.
4.save it as the same filename as number 1
thank you
-
Apr 8th, 2003, 10:29 AM
#16
Member
anybody ??
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
|