Python: can't create subdirectory -


i want apply test list of files. files past test should moved directory "pass"; others should moved directory "fail".

thus output directory should contain subdirectories "pass" , "fail".

here attempt:

        if(<scan==pass>) # working fine point             dest_dir = outdir + '\\' + 'pass'  # problem here             print("pass", xmlfile)             movefiletodirectory(indir, xmlfile, dest_dir)         else:             dest_dir = os.path.dirname(outdir + '\\' + 'fail')             print("fail: ", xmlfile)             movefiletodirectory(indir, xmlfile, dest_dir) 

however, code moving files output directory , not creating "pass" or "fail" subdirectories. ideas why?

use os.path.join(). example:

os.path.join(outdir, 'pass') 

see post

also, don't know movefiletodirectory does. use standard os.rename:

os.rename("path/to/current/file.foo", "path/to/new/desination/for/file.foo") 

see post

so:

source_file = os.path.join(indir, xmlfile) if(conditiontrue):     dest_file = os.path.join(outdir, 'pass', xmlfile)     print("pass: ", xmlfile) else:     dest_file = os.path.join(outdir, 'file', xmlfile)     print("fail: ", xmlfile) os.rename(source_file, dest_file) 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -