How do I join two paths in C#?

You have to use Path.Combine() as in the example below: string basePath = @”c:\temp”; string filePath = “test.txt”; string combinedPath = Path.Combine(basePath, filePath); // produces c:\temp\test.txt

How to find the largest file in a directory and its subdirectories?

Quote from this link- If you want to find and print the top 10 largest files names (not directories) in a particular directory and its sub directories $ find . -type f -printf ‘%s %p\n’|sort -nr|head To restrict the search to the present directory use “-maxdepth 1” with find. $ find . -maxdepth 1 -printf … Read more

Java, List only subdirectories from a directory, not files

You can use the File class to list the directories. File file = new File(“/path/to/directory”); String[] directories = file.list(new FilenameFilter() { @Override public boolean accept(File current, String name) { return new File(current, name).isDirectory(); } }); System.out.println(Arrays.toString(directories)); Update Comment from the author on this post wanted a faster way, great discussion here: How to retrieve a … Read more

How to write file if parent folder doesn’t exist?

As of Node v10, this is built into the fs.mkdir function, which we can use in combination with path.dirname: var fs = require(‘fs’); var getDirName = require(‘path’).dirname; function writeFile(path, contents, cb) { fs.mkdir(getDirName(path), { recursive: true}, function (err) { if (err) return cb(err); fs.writeFile(path, contents, cb); }); } For older versions, you can use mkdirp: … Read more