file system mapping

To map a file system and export the product into a spreadsheet I wrote the following short and handy Python script using the glob-module. The mapped drive and mapping depth can be determined by editing line 12. Line 16 determines the location, where the produced *.csv-File will be saved, and line 17 determines the column-separator of the *.csv-file.

This script was developed as part of my employment at the Federal Institute of Hydrology (BfG) in Koblenz, Germany.

#!/opt/Python-2.7.6/bin/python
# -*- coding: utf-8 -*-
# author: arnd.weber(at)bafg.de
# date: 2014.09.01

###
# load python modules
import os.path, glob

###
# glob.glob object with a depth of 4 levels, starting with the drive letter C: 
Depth4 = glob.glob(r"C:/*/*/*")

###
# export the list of folders (Depth4) to a file
filepath = r"C:/Users/arnd/Desktop/folders.csv"
separator = r";"
with open(filepath, "w") as file:
    for an_entry in Depth4:
        if os.path.isdir(an_entry):
            file.write(an_entry.replace(r"/",separator).replace(r"\\",separator) + r"\n")

###
# end the script and exit
exit(0)

 

Leave a Reply

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