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

Directory.Move doesn’t work (file already exist)

This method will move content of a folder recursively and overwrite existing files. You should add some exception handling. Edit: This method is implemented with a while loop and a stack instead of recursion. public static void MoveDirectory(string source, string target) { var stack = new Stack<Folders>(); stack.Push(new Folders(source, target)); while (stack.Count > 0) { … Read more

How to read all files in a folder using C

You can use this sample code and modify it if you need: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <dirent.h> #include <unistd.h> #include <errno.h> /* This is just a sample code, modify it to meet your need */ int main(int argc, char **argv) { DIR* FD; struct dirent* in_file; FILE *common_file; FILE *entry_file; … Read more

Difference between Package and Directory in Java

There is a relationship between package and directory, but it’s one that you must maintain. If you have a class that’s in “mypackage1.mypackage2”, that means that the java command is going to expect to find it in a directory structure named “mypackage1\mypackage2” (assuming “backwards” Windows notation), with that directory structure further embedded in a directory … Read more