简体   繁体   中英

python shutil.move moves directories with files fix

I was programming in python and I got something that I cannot fix. I have this code:

import shutil
import pathlib
import os

zdroj =(r'C:\Users\Acer\Desktop\New')
cil =(r'C:\Users\Acer\Desktop\New2')

files = os.listdir(zdroj)
print(files)
print (files)
for f in files:
        c = (r'\'' + f)
        c = c.split("'")
        shutil.move(str(zdroj) + c[0], str(cil))

But it move the folder too, anyone that can help me?

Try the following:

import shutil
import pathlib
import os

zdroj =(r'C:\Users\Acer\Desktop\New')
cil =(r'C:\Users\Acer\Desktop\New2')

files = os.listdir(zdroj)
print(files)
for f in files:
        src = os.path.join(zdroj, f)
        shutil.move(src, str(cil))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM