質問

I am trying to find some files, create a folder and move the files in there.

def test():
    try:
        logfile = "C:\\Users\\alkis\\Desktop\\testouter\\test"
        result_dir = os.path.join(logfile, "testzip")
        print result_dir
        os.makedirs(result_dir)
        os.chmod(result_dir, stat.S_IWRITE)
        kpath = logfile + "\\*.jpg"
        print kpath
        files = glob.glob(kpath)
        for file in files:
           filename = os.path.splitext(file)[0]
           print filename
           os.chmod(filename, stat.S_IWRITE)
           shutil.move(filename, result_dir)
    except Exception, e:
        #shutil.rmtree(result_dir)
        print e.__doc__ + "\r\n"
        print e.message
    return

The error I am getting is: MS-Windows OS call failed I check the permissions on my files and they are not read only.

役に立ちましたか?

解決

You are listing each file, removing the extension, then trying to move that filename.

The extension is part of the filename, don't remove it. Windows Exlorer hides the extension only when displaying files.

You also don't need to call os.chmod() on the filename; just skip that step:

for file in files:
    filename = os.path.splitext(file)[0]
    print filename
    shutil.move(filename, result_dir)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top