Copy the File Name to the New File & Move to Saparate Folder Using python

Copy the File Name to the New File & Move to Saparate Folder Using python

How to take the Each File name in the Folder and Move to Saparate Folder and Copy the File Name to the New File

Here is the Simple Demonstration for How to add take the Each File name in the Folder and Move to saparate Folder and Copy the File Name to the New File

def Create_Sitelist_Folder(self):
    new_dir = "scripts"
    dst_path = os.path.join(self.src_path, new_dir)
    os.mkdir(dst_path)
    fileslist = os.listdir(self.src_path)
    f = open(self.src_path + "/SitelistFull.txt", "w+")

    for l in fileslist:
        file_name, file_ext = os.path.splitext(l)
        if file_ext == '.mos':
            f.write(file_name)
            f.write("\n")
            shutil.move(os.path.join(self.src_path, l), dst_path)

Leave a Reply

Your email address will not be published. Required fields are marked *