How to check type of files without extensions? [duplicate]

There are Python libraries that can recognize files based on their content (usually a header / magic number) and that don’t rely on the file name or extension. If you’re addressing many different file types, you can use python-magic. That’s just a Python binding for the well-established magic library. This has a good reputation and … Read more

What tool to use to draw file tree diagram [closed]

Copying and pasting from the MS-DOS tree command might also work for you. Examples: tree C:\Foobar>tree C:. ├───FooScripts ├───barconfig ├───Baz │ ├───BadBaz │ └───Drop … tree /F C:\Foobar>tree C:. ├───FooScripts │ foo.sh ├───barconfig │ bar.xml ├───Baz │ ├───BadBaz │ │ badbaz.xml │ └───Drop … tree /A C:\Foobar>tree /A C:. +—FooScripts +—barconfig +—Baz ¦ +—BadBaz ¦ … Read more

Path.Combine absolute with relative path strings

What Works: string relativePath = “..\\bling.txt”; string baseDirectory = “C:\\blah\\”; string absolutePath = Path.GetFullPath(baseDirectory + relativePath); (result: absolutePath=”C:\bling.txt”) What doesn’t work string relativePath = “..\\bling.txt”; Uri baseAbsoluteUri = new Uri(“C:\\blah\\”); string absolutePath = new Uri(baseAbsoluteUri, relativePath).AbsolutePath; (result: absolutePath=”C:/blah/bling.txt”)

Get size of folder or file

java.io.File file = new java.io.File(“myfile.txt”); file.length(); This returns the length of the file in bytes or 0 if the file does not exist. There is no built-in way to get the size of a folder, you are going to have to walk the directory tree recursively (using the listFiles() method of a file object that … Read more

Check whether a path is valid in Python without creating a file at the path’s target

tl;dr Call the is_path_exists_or_creatable() function defined below. Strictly Python 3. That’s just how we roll. A Tale of Two Questions The question of “How do I test pathname validity and, for valid pathnames, the existence or writability of those paths?” is clearly two separate questions. Both are interesting, and neither have received a genuinely satisfactory … Read more