“OSError: [Errno 17] File exists” when trying to use os.makedirs [duplicate]
As of Python >=3.2, os.makedirs() can take a third optional argument exist_ok: os.makedirs(mydir, exist_ok=True)
As of Python >=3.2, os.makedirs() can take a third optional argument exist_ok: os.makedirs(mydir, exist_ok=True)
Here are some file systems which I found using google. TagFS – “Tag Semantics for Hierarchical File Systems” paper by Stephan Bloehdorn and Max Völkel, 2006 http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.60.4187 dhtfs – “Tagging based filesystem, providing dynamic directory hierarchies based on tags associated with files” a usable implementation, last release 2007 https://github.com/mayuresh/dhtfs Tagsistant – “A reasoning semantic filesystem … Read more
Silence all safe.directory warnings tl;dr Silence all warnings related to git’s safe.directory system. Be sure to understand what you’re doing. git config –global –add safe.directory ‘*’ Long version Adapted from this post on I cannot add the parent directory to safe.directory in Git. I had the same issue and resolved it by disabling safe directory … Read more
There are a couple of ways: pathlib.Path().rglob() Use pathlib.Path().rglob() from the pathlib module, which was introduced in Python 3.5. from pathlib import Path for path in Path(‘src’).rglob(‘*.c’): print(path.name) glob.glob() If you don’t want to use pathlib, use glob.glob(): from glob import glob for filename in glob(‘src/**/*.c’, recursive=True): print(filename) For cases where matching files beginning with … Read more
I Couldn’t get the above to work, but here is my implementation, i’ve tested it on c:\users on a “Win7” box, because if has all these “nasty” dirs: SafeWalk.EnumerateFiles(@”C:\users”, “*.jpg”, SearchOption.AllDirectories).Take(10) Class: public static class SafeWalk { public static IEnumerable<string> EnumerateFiles(string path, string searchPattern, SearchOption searchOpt) { try { var dirFiles = Enumerable.Empty<string>(); if(searchOpt == … Read more
Drop the leading slash on relativePath and it should work. The reason why this happens is that Path.Combine is interpreting relativePath as a rooted (absolute) path because, in this case, it begins with a \. You can check if a path is relative or rooted by using Path.IsRooted(). From the doc: If the one of … Read more
This is straight from Andrew Gerrand’s 10 things you (probably) don’t know about Go: var fs fileSystem = osFS{} type fileSystem interface { Open(name string) (file, error) Stat(name string) (os.FileInfo, error) } type file interface { io.Closer io.Reader io.ReaderAt io.Seeker Stat() (os.FileInfo, error) } // osFS implements fileSystem using the local disk. type osFS struct{} … Read more
I’m not sure how to do it other than by checking ifdefs inline char separator() { #ifdef _WIN32 return ‘\\’; #else return “https://stackoverflow.com/”; #endif } or (as suggested by PaperBirdMaster) const char kPathSeparator = #ifdef _WIN32 ‘\\’; #else “https://stackoverflow.com/”; #endif