How do I check wheter a file exists or not?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
How do I check wheter a file exists or not?
I tried to use if exists(special folder path blabla and filename) but it doesn't work.
-
- VIP Livecode Opensource Backer
- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: How do I check wheter a file exists or not?
Hi, one of the things is to make sure LiveCode is looking in the correct folder - also - use the "is there a file" format...
EDIT: the exists() function is only for controls, not files or folders...
Code: Select all
put "testfile.txt" into tFile
set itemdel to slash
put item 1 to -2 of the effective filename of the current stack & slash & tFile into tPath
if there is a file tPath then
answer "aye"
else
answer "nay"
end if
"...this is not the code you are looking for..."
Re: How do I check wheter a file exists or not?
Thanks Dave 
It's working perfectly, but I don't really understand what this means, can you explain what it means please?

It's working perfectly, but I don't really understand what this means,
Code: Select all
put item 1 to -2 of the effective filename of the current stack & slash & tFile into tPath
-
- VIP Livecode Opensource Backer
- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: How do I check wheter a file exists or not?
Hi - that line was just to set things up for the sample code...
Getting the effective filename of the current stack will produce the name and location of the stack you are working on - for example it might be something like "/Users/dave/Dropbox/LC/some-project/testStack.livecode"
Setting the itemdel (short for item delimiter) to slash allows us to split up the effective filename by slash
Getting item 1 to -2 (getting all the items up to the second-last one) gives us the location of the folder holding the stack we are working on
Then after that all we do is add a slash to the end of the resulting string and after that add the file name we are looking for
Please note that the sample code I sent you was for checking files in the same folder as the current stack - you would have to set up things to look in a different folder if you wanted to check files elsewhere...
Getting the effective filename of the current stack will produce the name and location of the stack you are working on - for example it might be something like "/Users/dave/Dropbox/LC/some-project/testStack.livecode"
Setting the itemdel (short for item delimiter) to slash allows us to split up the effective filename by slash
Getting item 1 to -2 (getting all the items up to the second-last one) gives us the location of the folder holding the stack we are working on
Then after that all we do is add a slash to the end of the resulting string and after that add the file name we are looking for
Please note that the sample code I sent you was for checking files in the same folder as the current stack - you would have to set up things to look in a different folder if you wanted to check files elsewhere...
"...this is not the code you are looking for..."
Re: How do I check wheter a file exists or not?
I think I get it now.
And what if I want to look for the file in the desktop, or my documents, how do I do that?
EDIT: And also, how do I create a file in the same location as the exported .exe file?
And what if I want to look for the file in the desktop, or my documents, how do I do that?
EDIT: And also, how do I create a file in the same location as the exported .exe file?
Re: How do I check wheter a file exists or not?
Look up "specialfolderpath" in the dictionary, that is exactly what you are looking for!AgentItay wrote:And what if I want to look for the file in the desktop, or my documents, how do I do that?
Dave already answered (and explained the script) in his last posting(s)...AgentItay wrote:EDIT: And also, how do I create a file in the same location as the exported .exe file?

Re: How do I check wheter a file exists or not?
Right, managed to do it 
Thank you very much.

Thank you very much.