Pregunta

I have a whole bunch of files in a directory. I'd like a program to loop over the files in the directory and prompt me to enter the name of directory (which are all in the same directory) so that the program moves the file to the specified directory.

I'd like a terminal solution, more specifically, Python way would be instructive for me

¿Fue útil?

Solución

Your question is a bit vauge on what you need help with, but here is a template to get you started. Use os and shutil to list directories and move files.

import shutil, os

target = raw_input("Target directory: ")

# Make sure the target dir exists!
assert(os.path.exists(target))

for f in os.listdir('.'):
    b = raw_input("Press y to move file %s to %s: " %(f,target))
    if b.lower() == 'y':
        shutil.move(f, target)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top