How do I create a directory, and any missing parent directories?

On Python ≥ 3.5, use pathlib.Path.mkdir: from pathlib import Path Path(“/my/directory”).mkdir(parents=True, exist_ok=True) For older versions of Python, I see two answers with good qualities, each with a small flaw, so I will give my take on it: Try os.path.exists, and consider os.makedirs for the creation. import os if not os.path.exists(directory): os.makedirs(directory) As noted in comments … Read more

How can I find all files containing specific text (string) on Linux?

Do the following: grep -rnw ‘/path/to/somewhere/’ -e ‘pattern’ -r or -R is recursive, -n is line number, and -w stands for match the whole word. -l (lower-case L) can be added to just give the file name of matching files. -e is the pattern used during the search Along with these, –exclude, –include, –exclude-dir flags … Read more

Is there a faster way than this to find all the files in a directory and all sub directories?

Try this iterator block version that avoids recursion and the Info objects: public static IEnumerable<string> GetFileList(string fileSearchPattern, string rootFolderPath) { Queue<string> pending = new Queue<string>(); pending.Enqueue(rootFolderPath); string[] tmp; while (pending.Count > 0) { rootFolderPath = pending.Dequeue(); try { tmp = Directory.GetFiles(rootFolderPath, fileSearchPattern); } catch (UnauthorizedAccessException) { continue; } for (int i = 0; i < … Read more

How can I recursively delete folder with a specific name with PowerShell?

This one should do it: get-childitem -Include .svn -Recurse -force | Remove-Item -Force -Recurse Other version: $fso = New-Object -com “Scripting.FileSystemObject” $folder = $fso.GetFolder(“C:\Test\”) foreach ($subfolder in $folder.SubFolders) { If ($subfolder.Name -like “*.svn”) { remove-item $subfolder.Path -Verbose } }

java.util.zip – Recreating directory structure

The URI class is useful for working with relative paths. File mydir = new File(“C:\\mydir”); File myfile = new File(“C:\\mydir\\path\\myfile.txt”); System.out.println(mydir.toURI().relativize(myfile.toURI()).getPath()); The above code will emit the string path/myfile.txt. For completeness, here is a zip method for archiving a directory: public static void zip(File directory, File zipfile) throws IOException { URI base = directory.toURI(); Deque<File> … Read more

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