directory - How can I scrape file names and create directories for each filename in Python? -


i'm trying scrape filenames inside folder , make directories each filename inside folder. i've got far when run it, doesn't create new folders in destination folder. when run in terminal doesn't return errors.

import os import shutil  folder = "/home/ro/downloads/uglybettyfanfiction.net/" destination = "/home/ro/a python scripts/dest_test/"  # each files path name  def ensure_dir(f):     d = os.path.dirname(f)     if not os.path.exists(d):         os.makedirs(d)  files in os.listdir(folder):     new_path = folder + files     ensure_dir(new_path) 

you've got few mistakes. no need use dirname , should write destination, not same folder:

def ensure_dir(f):     if not os.path.exists(f):         os.mkdir(f)  files in os.listdir(folder):     new_path = destination + files     ensure_dir(new_path) 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -