0

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?

Hemerson Tacon
  • 2,419
  • 1
  • 16
  • 28
ScreaMyCZE
  • 65
  • 1
  • 6

1 Answers1

0

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))
Hemerson Tacon
  • 2,419
  • 1
  • 16
  • 28
  • Dude thanks, it is working but where i have the mistake? I will accept the answer then – ScreaMyCZE Mar 05 '19 at 20:20
  • 1
    When you did `c = (r'\'' + f)` and then `c = c.split("'")` you made `c[0]` have only the slash `\\`, then your source folder was the root directory – Hemerson Tacon Mar 05 '19 at 20:22