Monday, 19 October 2020

Python script that creates a copy of the same folders structure

Hello, it has been a while since I last posted something. Today, I wrote a very short script but something that could be useful so I thought it worth sharing and keeping into my blog. So have you ever wanted to copy and paste multiple folders without their content! This is what the following python function with automatically do for you:
import os

def creatFolders(i_inDir,i_outDir):
   dirs=[d[0] for d in os.walk(".")]
   for d in dirs:
      if not os.path.exists(d):
The following scripts returns all the files from a direction with a given extension:
import os

def getFiles(i_inDir,i_ext):
    images=[f for f in os.listdir(".")if f.endswith(i_ext)] 
    print (images)
    print ("Images in Dir")
    print (i_inDir)
    return images
This script was developed as part of the "ASTARTE"(EXCELLENCE/0918/0341) project, which is co-financed by the European Regional Development Fund and the Republic of Cyprus through the Research Innovation Foundation. | Powered By Copywriter WordPress Theme.

No comments:

Post a Comment