How to copy a file along with directory structure/path using python? [duplicate]

To create all intermediate-level destination directories you could use os.makedirs() before copying: import os import shutil srcfile=”a/long/long/path/to/file.py” dstroot=”/home/myhome/new_folder” assert not os.path.isabs(srcfile) dstdir = os.path.join(dstroot, os.path.dirname(srcfile)) os.makedirs(dstdir) # create all directories, raise an error if it already exists shutil.copy(srcfile, dstdir)

How to scan a folder in Java?

Not sure how you want to represent the tree? Anyway here’s an example which scans the entire subtree using recursion. Files and directories are treated alike. Note that File.listFiles() returns null for non-directories. public static void main(String[] args) { Collection<File> all = new ArrayList<File>(); addTree(new File(“.”), all); System.out.println(all); } static void addTree(File file, Collection<File> all) … Read more

Compressing directory using shutil.make_archive() while preserving directory structure

Using the terms in the documentation, you have specified a root_dir, but not a base_dir. Try specifying the base_dir like so: shutil.make_archive(‘/home/code/test_dicoms’, ‘zip’, ‘/home/code/’, ‘test_dicoms’) To answer your second question, it depends upon the version of Python you are using. Starting from Python 3.4, ZIP64 extensions will be availble by default. Prior to Python 3.4, … Read more

Using bash, how do you make a classpath out of all files in a directory?

[*] New Answer (October 2012) There’s no need to manually build the classpath list. Java supports a convenient wildcard syntax for directories containing jar files. java -cp “$LIB/*” (Notice that the * is inside the quotes.) Explanation from man java: As a special convenience, a class path element containing a basename of * is considered … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)