How to move files in a folder and its sub-directory folders to a target folder in Python

preview_player
Показать описание
Your donation will help me to continue to make more tutorial videos!

File management is something that we deal with almost everyday. Imaging one day you have to move all the files from some folders and its child folders to a specific folder, and imaging you have to do it one-by-one for many folders. In this video I will show you how to write a Python script to automate the process.

Visit my website

For questions, please email me at

#PythonTutorial LearnPythonProgramming #PythonProgramming
Рекомендации по теме
Комментарии
Автор

You are the master on this! Keep up the good work!

JecasaLtd
Автор

I have a folder full of .jpg files how do I move 25 randomly selected .jpgs from the folder and move them into a new folder "I want it to automatically create the folder when i automate the move" and have it repeat until all the files have been moved from the source folder. Thanks

dustonmeyer
Автор

Thank you Jie.
Out of curiosity, why does your file path work with \ and mine only works with /. Is there a reason for this?
Again, thank you! really helped with my understanding of implementing os.walk

BySixa
Автор

Hi, can you guide me if I want to move files from different locations into one location?

wakkiephone
Автор

I have a problem I have installed pil in pydroid now I want to know how to import PNG files into pil please help I am a beginner so I can open images

angelaepakalibimbi
Автор

Question, (the code and this video have been of real help) can I set 'file' to file = "ReadCMI" which is a file?!

rockrollandfunk
Автор

what if i have 3 sub-folders in 1 parent folder and i only want select files from only 1 sub-folders to other folder? Something like Main folder 1- Kid Cloth | Inside this parent folder is thousand of sub-folder as 1.1-socer blue shirt; 1.2-socer yellow shirt; 1.3-socer white shirt....1.1000-socer colorful shirt---> and inside each of this sub-folder is 3 other sub-folder as 1.1.1-main photo; 1.1.2-detail page photo; 1.1.3-variations photos. Now i want to select all image file only from sub-folder 1.1.3-variations photos to 1 other Folder....and it from thousand of other sub-folder. What can I do?

annietrinh
Автор

I don't understand why you are typing
if file: <-
the statement for the 'if' it's not like the ones I've learned

EtBukaneluu
Автор

why we should add '\\' at the end of the file path?

bingqingzhu
Автор

Could you please help me to write a code to remove empty subfolders after copying all files into the parent directory ?. You have written code to move files, so, I want to remove empty folders.

ramyainchara
Автор

can u please write a code for move subfolders to specified folder with files

peddinenivinitha
Автор

sir when we use shutil move then this error shows how can close this file before move plz reply
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: '20200814124216.wav'

rinkiyadav