Created
April 14, 2023 07:45
-
-
Save LenAnderson/140fa59a9b299f9e315f66d25dc7b793 to your computer and use it in GitHub Desktop.
simple python script to merge multiple CSV exports from WizTree into a single file that can be loaded back into WizTree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def main(): | |
""" | |
- Save this file somewhere. | |
- In the directory where this file is saved, create a directory named "in". | |
- Put all your CSV exports from WizTree into the "in" directory. | |
- Run this script. | |
- A directory "out" will be created with a file "WizTree_merged.csv". | |
""" | |
# create output folder if it doesn't exist | |
if not os.path.exists('out'): | |
os.makedirs('out') | |
# start writing to the output file | |
with open(os.path.join('out', 'WizTree_merged.csv'), 'w', encoding='utf-8') as fout: | |
header = False | |
# loop through all files in the "in" folder | |
for f in os.scandir('in'): | |
with open(f, 'r') as fin: | |
# first line is the "generated by WizTree" message, skip that | |
fin.readline() | |
# second line has column headers, only write those once | |
line = fin.readline() | |
if not header: | |
fout.write(line) | |
header = True | |
line = fin.readline() | |
while line: | |
# put the fake root at the top of each files path and remove | |
# the colon from the original drive letter | |
fout.write(f'"FakeRoot:\\{line[1:].replace(":","", 1)}') | |
line = fin.readline() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment