To check if Folder exists in Python you can use the snippet below.
import os print(os.path.exists("/myfolder/folder1"))
To check if Folder exists in Python you can use the snippet below.
import os print(os.path.exists("/myfolder/folder1"))
To check if a Object has an Attribute in Python you can use the snippet below.
if hasattr(myObject, 'myAttributeName'): # myObject.myAttributeName exists.
To check if a variable exists in Python, you can use the snippet below.
if 'myVariable' in locals(): # myVariable exists locally. if 'myVariable' in globals(): # myVariable exists globally.
To check if a Table exists in SQLite you can use the following snippet.
SELECT name FROM sqlite_master WHERE type='table' AND name='TableName'; -- temp tables can be selected by using ... FROM sqlite_temp_master ...
To check if a file exists in C++ you can use the following snippet.
#include <sys/stat.h> inline bool fileExists (const std::string& fileName) { struct stat buff; return (stat (fileName.c_str(), &buff) == 0); }
To check if a file exists in C you can use the follwing snippet.
#include <unistd.h> int fileExists(const char *filename) { return !access(filename, F_OK); }
To check if file or folder exists in Powershell you can use the following snippet.
if(test-path "C:\Users\Codesnippets\Desktop\Test.xml") { echo "exists!" } else { echo "not exists!" }
if(test-path "C:\Users\Codesnippets\Desktop") { echo "exists!" } else { echo "not exists!" }
To check if a file exists in Java you can use the following snippet.
String filePath = "C:\\Users\\Codesnippets\\Desktop\\Test.xml"; File file = new File(filePath); if (file.exists()) { System.out.println("file " + filePath + " does exists!"); } else { System.out.println("file " + filePath + " does not exists!"); }