문제

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

도움이 되었습니까?

해결책

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top