Deleting all files in a directory with Python

Via os.listdir and os.remove: import os filelist = [ f for f in os.listdir(mydir) if f.endswith(“.bak”) ] for f in filelist: os.remove(os.path.join(mydir, f)) Using only a single loop: for f in os.listdir(mydir): if not f.endswith(“.bak”): continue os.remove(os.path.join(mydir, f)) Or via glob.glob: import glob, os, os.path filelist = glob.glob(os.path.join(mydir, “*.bak”)) for f in filelist: os.remove(f) Be … Read more

Python Pandas: How to read only first n rows of CSV files in?

If you only want to read the first 999,999 (non-header) rows: read_csv(…, nrows=999999) If you only want to read rows 1,000,000 … 1,999,999 read_csv(…, skiprows=1000000, nrows=999999) nrows : int, default None Number of rows of file to read. Useful for reading pieces of large files* skiprows : list-like or integer Row numbers to skip (0-indexed) … Read more

getResourceAsStream() vs FileInputStream

The java.io.File and consorts acts on the local disk file system. The root cause of your problem is that relative paths in java.io are dependent on the current working directory. I.e. the directory from which the JVM (in your case: the webserver’s one) is started. This may for example be C:\Tomcat\bin or something entirely different, … Read more

How to write a UTF-8 file with Java?

Instead of using FileWriter, create a FileOutputStream. You can then wrap this in an OutputStreamWriter, which allows you to pass an encoding in the constructor. Then you can write your data to that inside a try-with-resources Statement: try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(PROPERTIES_FILE), StandardCharsets.UTF_8)) // do stuff }

How to delete a file via PHP?

The following should help realpath — Returns canonicalized absolute pathname is_writable — Tells whether the filename is writable unlink — Deletes a file Run your filepath through realpath, then check if the returned path is writable and if so, unlink it.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)