0

I'm trying to copy images in a directory using Python 2.7.12. The problem is that I want to only move the files within the Directory and not the Directory. So in bash it would look something like

    cp /path/to/source/* . /path/to/destination

but I want to do this in Python 2.7.12. I know how to copy the directory using things like shutil.copy but you can't add the /* to move the files within the directory. I'm kind of new to python and Stack Overflow so I'm sorry if there is any errors or confusion.

Asori12
  • 133
  • 1
  • 14
  • 2
    you can use the `/*` notation with [glob.glob(pathname)](https://docs.python.org/2/library/glob.html#glob.glob) to get a list of filenames, then pass them to `shutil.copy` as in this answer [python copy files by wildcards](https://stackoverflow.com/a/18372078/1248974) – chickity china chinese chicken Aug 02 '17 at 17:05
  • would I have to put the glob.glob(pathname) inside of the the shutil.copy or how would I pass it. Sorry I'm kinda new haha. – Asori12 Aug 02 '17 at 17:16
  • 1
    do it almost exactly the same as that linked answer, but since you want to copy *all* files, just change the one line `for filename in glob.glob(r'/path/to/source/*'):`, so the `*` will get *all* the files in the `destination` directory, and not just those with `*.txt` extensions. If you prefer I can put it all in an easier to read answer with formatting, but it's really just changing a couple of lines. – chickity china chinese chicken Aug 02 '17 at 17:22
  • 1
    ^^ sorry, I typo'd, I meant to say "so the `*` will get *all* the files in the ***source*** directory", but I think (hope?) you get the idea. – chickity china chinese chicken Aug 02 '17 at 17:47
  • 1
    Yes I figured it out thanks for the help! – Asori12 Aug 02 '17 at 18:14

1 Answers1

1

You could just use cmd terminal if your a windows user. Type in help Robocopy and it should display different options