How to Test for If Two Files Exist

How to test for if two files exist?

Try adding an additional square bracket.

if [[ -f .ssh/id_rsa && -f .ssh/id_rsa.pub ]]; then

Execute a Command if Two Files Exist

You need to separate the tests into their own square brackets:

if [ -e file ] && [ -e file ]; then
echo "wow"
fi

How to check if two files exist

Try this:

You need to check the file existence separately.

if (file_exists($admin) && file_exists($catalog)) {
$route['default_controller'] = "upgrade/index";
$route['404_override'] = '';
} else {
$route['default_controller'] = "step_1/index";
$route['404_override'] = '';
}

You can read on the manual, file_exists.

How to test if multiple files exist using a Bash script

To avoid "too many arguments error", you need xargs. Unfortunately, test -f doesn't support multiple files. The following one-liner should work:

for i in /var/log/apache2/access.log.*; do test -f "$i" && echo "exists one or more files" && break; done

By the way, /var/log/apache2/access.log.* is called shell-globbing, not regexp. Please see Confusion with shell-globbing wildcards and Regex for more information.

Check if two files exist, then if they do, run batch file

check the first, then the next, if the first does not match, it will not attempt the second, if it does it will attempt the second but not run the command if second file not found:

if exist "c:\file1.txt" if exist "c:\file2.txt" msiexec /I "\SERVER...\application.msi"

Check whether two files exist (in shell script)

if [ -e File1Name -a -e File2Name ]
then
echo Yes
else
echo No
fi

Check if the two Files exist in the folder

Like this?

        string path = @"";
DirectoryInfo dir = new DirectoryInfo(path);
var files = dir.GetFiles("*.txt");
if (files.Length >= 2)
{

}

How to check two file exist in same folder?

Do this

File yourDir = new File(Environment.getExternalStorageDirectory(), "Testapp");
for (File f : yourDir.listFiles()) {
if (f.isFile()){
String name = f.getName();
if(name.equals("music1.mp3")) {
// music1.mp3 present
} else if(name.equals("music2.mp3")) {
// music2.mp3 present
}
}
}

More efficient way as suggested by @Henry below in comments

File file1 = new File(Environment.getExternalStorageDirectory()+"/Testapp/music1.mp3");
File file2 = new File(Environment.getExternalStorageDirectory()+"/Testapp/music2.mp3");
if (file1.exists()) {
// music1.mp3 present
} else if (file2.exists()) {
// music2.mp3 present
}

Regex to check if multiple files exist using one if then statement

What you're trying to do isn't working because you're trying to do two checks in one.

Try changing this line

 if [ -s ${PREFIX}_R[1,2].fastq ] 

to this

if [ -s ${PREFIX}_R1.fastq ] && [ -s ${PREFIX}_R2.fastq ]; then


Related Topics



Leave a reply



Submit