I have a shapefile with two columns with links to directory and/or file and NULL Each record has a columns 'NAME. Something like this

...  NAME   HOTLINK1                  HOTLINK2
...  name1  C:\...\directory1         C:\...\directory6\file
...  name2  C:\...\directory2         NULL
...  name3  C:\...\directory5\file    C:\...\directory
...  name4  NULL                      NULL

whit the code below I can create a folder for every record in "NAME" if not exist:

import os

layer = iface.activeLayer()
idx = layer.fieldNameIndex('NAME')  
path = "path/to/directory"

for feat in layer.getFeatures():
    attrs = feat.attributes()
    if not os.path.exists(path + attrs[idx]):
        os.makedirs(path + attrs[idx])

Now I would need develop this code so as to copy the entire contents of the directory (subdirectories included) and the file from HOTLINK1 and HOTLINK2 to new directory 'NAME'.


  • if HOTLINK is a directory >>> copy the entire contents of the directory (subdirectories included)

  • if HOtLINK is a file >>> copy the file

  • if is NULL >> pass.

  • 1
    What have you tried? GIS SE is less about "I need to develop this code" and more about "Here's this code I've written, but it doesn't run right" (with examples of input and print statements in the code to follow flow of control) – Vince Feb 13 '17 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.