Skip to content

Instantly share code, notes, and snippets.

@LenAnderson
Created April 14, 2023 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LenAnderson/140fa59a9b299f9e315f66d25dc7b793 to your computer and use it in GitHub Desktop.
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
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