Is the path for a file an absolute path (i.e. fully qualified)?
absolute-path?: func [file] [file = clean-path file]
11379 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
absolute-path?: func [file] [file = clean-path file]
dirize-ex: func [val] [dirize to file! val]
#return fnmatch.fnmatch(self.name, pattern) # poor man's fnmatch pattern = pattern.replace('.', '\\.').replace('*','.*').replace('?','.') return re.match(pattern, self.name)
# with os.path.walk def delete_backups(arg, dirname, names): for name in names: if name.endswith('~'): os.remove(os.path.join(dirname, name)) os.path.walk(os.environ['HOME'], delete_backups, None) # with os.path, if (like me) you can never remember how os.path.walk works def walk_tree_delete_backups(dir): for name in os.listdir(dir): path = os.path.join(dir, name) if os.path.isdir(path): walk_tree_delete_backups(path) elif name.endswith('~'): os.remove(path) walk_tree_delete_backups(os.environ['HOME']) # with path dir = path(os.environ['HOME']) for f in dir.walk(): if f.isfile() and f.endswith('~'): os.remove(f)
qualify: func [
"Prepend a qualifier/path to all files in a block."
files [any-block!]
path [file! url! string!]
] [
foreach file files [insert file path]
files
]
# make some files excutable d = path('/usr/home/guido/bin') for f in d.files('*.py'): f.chmod(0755) # Directory walking - delete Emacs backup files d = path(os.environ['HOME']) for f in d.walkfiles('*~'): f.remove()
#!/usr/bin/env python # -*- coding: utf-8 -*- import os,sys if __name__ == "__main__": _path = os.path.split(sys.argv[0])[0] if _path: os.chdir(_path)
java -Dpython.path="%GUESS_HOME%\src\Lib" -classpath "..."
function canonical_path($path) { $canonical = preg_replace('|/\.?(?=/)|','',$path); while (($collapsed = preg_replace('|/[^/]+/\.\./|','/',$canonical,1)) !== $canonical) { $canonical = $collapsed; } $canonical = preg_replace('|^/\.\./|','/',$canonical); return $canonical; }