This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
uphp:functions:file_exists [2017/03/06 12:39] jeff |
uphp:functions:file_exists [2021/09/13 05:57] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
======file_exists====== | ======file_exists====== | ||
+ | |||
< | < | ||
Line 5: | Line 6: | ||
====Description==== | ====Description==== | ||
- | <well size=" | + | |
- | <span style=" | + | <well size=" |
- | < | + | <span style=" |
- | <span style=" | + | <span style=" |
- | <span style=" | + | <span style=" |
- | <span style=" | + | <span style=" |
+ | <span style=" | ||
</ | </ | ||
Return 1 (true) if the file exists, otherwise return 0 (false) | Return 1 (true) if the file exists, otherwise return 0 (false) | ||
- | ====Parameters==== | + | ====Parameter==== |
- | < | + | |
- | ====Return | + | < |
- | 1 if file exists, 0 if file does not exist | + | |
+ | ====Return | ||
+ | |||
+ | < | ||
====Examples==== | ====Examples==== | ||
- | **Example #1** - Simple existence report: | + | |
+ | ===Simple existence report=== | ||
<code php> | <code php> | ||
< | < | ||
- | if (file_exists("/ | + | |
- | print(" | + | print(" |
- | } else { | + | } else { |
- | print(" | + | print(" |
- | } | + | } |
?></ | ?></ | ||
</ | </ | ||
- | **Example #2** - Create a new file with a unique non-conflicting filename | + | ===Create a new file with a unique non-conflicting filename=== |
+ | |||
+ | This example is extracted from the Wattmon OS "/ | ||
<code php> | <code php> | ||
<? | <? | ||
- | $date=strftime("/ | + | |
- | $cnt=0; | + | $cnt=0; |
- | while (file_exists($date)) { | + | while (file_exists($date)) { |
- | $date=strftime("/ | + | $date=strftime("/ |
- | $cnt++; | + | $cnt++; |
- | } | + | } |
- | $st="/ | + | $st="/ |
- | if (file_exists($st)) { | + | if (file_exists($st)) { |
- | $res=rename($st, | + | $res=rename($st, |
- | if ($res==0) $_GLOBALS[' | + | if ($res==0) $_GLOBALS[' |
- | log(" | + | log(" |
- | } else { | + | } else { |
- | $_GLOBALS[' | + | $_GLOBALS[' |
- | } | + | } |
- | print(" | + | print(" |
?> | ?> | ||
</ | </ | ||
====See Also==== | ====See Also==== | ||
+ | |||
[[findfirst()]] - Start searching the current folder for files matching a pattern and attributes | [[findfirst()]] - Start searching the current folder for files matching a pattern and attributes | ||
- | [[strftime()]] - Format | + | [[strftime()]] - Format |
[[time()]] - Return the current system timestamp | [[time()]] - Return the current system timestamp | ||
- | [[rename()]] - Rename or move a file from source to destination | + | [[rename()]] - Rename or move a file or directory |
- | + | ||
- | [[log()]] - Print to the System Log | + | |
- | + | ||
- | [[uphp: | + | |
- | [[uphp: | + | [[log()]] - Print to the System Log (or optional file) |
[[uphp: | [[uphp: | ||