checking_20whether_20a_20directory_20exists
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
checking_20whether_20a_20directory_20exists [2018/03/31 13:19] – external edit 127.0.0.1 | checking_20whether_20a_20directory_20exists [2024/01/05 00:22] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
//by Richard Russell, May 2006, amended May 2010//\\ \\ It's easy to check whether a file exists: you just try to open it:\\ | //by Richard Russell, May 2006, amended May 2010//\\ \\ It's easy to check whether a file exists: you just try to open it:\\ | ||
+ | <code bb4w> | ||
DEF FNcheckfile(file$) | DEF FNcheckfile(file$) | ||
LOCAL F% | LOCAL F% | ||
Line 7: | Line 8: | ||
IF F% CLOSE #F% | IF F% CLOSE #F% | ||
= F% | = F% | ||
+ | </ | ||
This function returns a non-zero value if the file exists and zero if not (strictly speaking it may also return zero if the file exists but is not accessible, but that's usually what is wanted).\\ \\ To check for the existence of a directory (folder) you can use the fact that the ' | This function returns a non-zero value if the file exists and zero if not (strictly speaking it may also return zero if the file exists but is not accessible, but that's usually what is wanted).\\ \\ To check for the existence of a directory (folder) you can use the fact that the ' | ||
+ | <code bb4w> | ||
DEF FNcheckdir(dir$) | DEF FNcheckdir(dir$) | ||
LOCAL F% | LOCAL F% | ||
Line 13: | Line 16: | ||
IF F% CLOSE #F% | IF F% CLOSE #F% | ||
= F% | = F% | ||
- | This function returns a non-zero value if the directory exists and zero if not. \\ \\ If you want to know whether a file **or** directory with a given name exists you can use a combination of the above functions. However an alternative is to use Windows API calls: | + | </ |
+ | This function returns a non-zero value if the directory exists and zero if not. | ||
+ | |||
+ | If you want to know whether a file **or** directory with a given name exists you can use a combination of the above functions. However an alternative is to use Windows API calls: | ||
+ | <code bb4w> | ||
DEF FNcheckdir(name$) | DEF FNcheckdir(name$) | ||
LOCAL dir%, sh% | LOCAL dir%, sh% | ||
Line 21: | Line 28: | ||
IF sh%<> | IF sh%<> | ||
= 8 - (!dir% AND 16) | = 8 - (!dir% AND 16) | ||
+ | </ | ||
This function returns a negative value if a directory with the specified name exists, a positive value if a file of that name exists, and zero if neither a file nor a directory of that name exists. | This function returns a negative value if a directory with the specified name exists, a positive value if a file of that name exists, and zero if neither a file nor a directory of that name exists. |
checking_20whether_20a_20directory_20exists.1522502349.txt.gz · Last modified: 2024/01/05 00:18 (external edit)