Reputation: 233
I have files (like 1, 2, 3, 4, 5, and so on) placed inside a directory ("docs"). Now I want to move these files to a different directory ("example") which should contain subfolders 1, 2, 3, 4, ... . The files should be placed accordingly (like subfolder 1 should contain the file 1 from the folder "docs," file 2 in subfolder 2, and so on). Please provide some pointers on how to achieve this using a Python script.
Upvotes: 1
Views: 56
Reputation: 233
import os
import glob
import re
import os, sys
import io
from os.path import join, expanduser
j=1
RootDir1 = r'C:/users/hp/RadImagesFilpng/'
TargetFolder = r'C:/users/hp/Radpngcopy/copy'
for root, dirs, files in os.walk((os.path.normpath(RootDir1)), topdown=False):
for name in files:
if name.endswith('.html'):
print ("Found")
SourceFolder = os.path.join(root,name)
shutil.copy2(SourceFolder, TargetFolder)
This works for me
Upvotes: 1