is_file or file_exists in PHP

is_file() will return false if the given path points to a directory. file_exists() will return true if the given path points to a valid file or directory. So it would depend entirely on your needs. If you want to know specifically if it’s a file or not, use is_file(). Otherwise, use file_exists().

How to write to a CSV line by line?

General way: ##text=List of strings to be written to file with open(‘csvfile.csv’,’wb’) as file: for line in text: file.write(line) file.write(‘\n’) OR Using CSV writer : import csv with open(<path to output_csv>, “wb”) as csv_file: writer = csv.writer(csv_file, delimiter=”,”) for line in data: writer.writerow(line) OR Simplest way: f = open(‘csvfile.csv’,’w’) f.write(‘hi there\n’) #Give your csv text … Read more

Copy file with pathlib in Python

To use shutil.copy: import pathlib import shutil my_file = pathlib.Path(‘/etc/hosts’) to_file = pathlib.Path(‘/tmp/foo’) shutil.copy(str(my_file), str(to_file)) # For Python <= 3.7. shutil.copy(my_file, to_file) # For Python 3.8+. The problem is pathlib.Path create a PosixPath object if you’re using Unix/Linux, WindowsPath if you’re using Microsoft Windows. With older versions of Python, shutil.copy requires a string as its … Read more