In most cases, you can use test commands to test the conditions. For example, you can compare strings, determine whether a file exists, and whether the file is readable. The following article describes how to use BashShell to check whether a file
$filename = '/path/to/foo.txt ';
if (file_exists ($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
Copy CodeIf the file is present, the
Press function access, header file IO.h (Linux by using Unistd.hint access (const char *filename, int amode);A amode parameter of 0 indicates the existence of the check file, assuming the file exists. Returns 0. Does not exist, returns-1.This
A simple way to determine whether a file or directory exists 1.c++ in C + +: #include #include using namespace Std;#define FILENAME "Stat.dat"int main (){FStream _file;_file.open (filename,ios::in);if (!_file){cout}Else{cout}return 0;}2. Ways to use
1.c++ is an easy way to do this:
Copy Code code as follows:
#include
#include
using namespace Std;
#define FILENAME "Stat.dat"
int main ()
{
FStream _file;
_file.open (filename,ios::in);
if (!_file)
{
cout}
http://blog.csdn.net/roger_77/article/details/1538447/A simple way to determine whether a file or directory exists 1.c++ in C + +: #include #include using namespace Std;#define FILENAME "Stat.dat"int main (){FStream _file;_file.open
From: 1538447/1.c++ a very simple way: #include #include using namespace Std;#define FILENAME "Stat.dat"int main (){FStream _file;_file.open (filename,ios::in);if (!_file){cout}Else{cout}return 0;}2. Ways to use the C-language library:Name of
C language to determine whether a file exists
Use Function access. The header file is Io. H. prototype:
Int access (const char * filename, int amode );
If the amode parameter is 0, the object existence is checked. If the object exists, 0 is
I forgot what I saw there. Write it here and record it.
1) Access2) fopen3) stat fstat?
>>>>>Function access should be used. The header file is Io. H. prototype:
Int access (const char * filename, int amode );
If the amode parameter is 0, the
Write a script to check whether a file exists. If so, output its details. If not, the system prompts that the output file does not exist. Before providing this script, let's take a look at the following commands: file upload.zip.
1. # ll-h
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.