I am currently exporting a number of maps in pdf format using Data Driven Pages.
I would like to be able to export, or move each pdf map once exported, to a separate folder which is named with the pdf name.
Once exported the maps have to be imported in to a CRM system and having each map in a separate folder would expedite this process.
Solved! Go to Solution.
Could this be a solution for you?
import glob, os, shutil
from shutil import copyfile
inPath = r"yourPath"
outPath = r"yourPath"
for file in glob.glob(os.path.join(inPath, "*.pdf")):
outFolder = os.path.basename(file[:-4])
if os.path.isdir(os.path.join(outPath, outFolder)):
shutil.rmtree(os.path.join(outPath, outFolder))
else:
pass
outDir = os.mkdir(os.path.join(outPath, outFolder))
outDir1 = os.path.join(outPath, outFolder)
outFile = os.path.join(outDir1, os.path.basename(file))
copyfile(file, outFile)
Could this be a solution for you?
import glob, os, shutil
from shutil import copyfile
inPath = r"yourPath"
outPath = r"yourPath"
for file in glob.glob(os.path.join(inPath, "*.pdf")):
outFolder = os.path.basename(file[:-4])
if os.path.isdir(os.path.join(outPath, outFolder)):
shutil.rmtree(os.path.join(outPath, outFolder))
else:
pass
outDir = os.mkdir(os.path.join(outPath, outFolder))
outDir1 = os.path.join(outPath, outFolder)
outFile = os.path.join(outDir1, os.path.basename(file))
copyfile(file, outFile)
Perfect, thanks for that Johannes. That works perfectly.