DDP: Move Exported PDF to Separate Folder

238
2
Jump to solution
12-09-2019 04:52 AM
PaulGardiner
New Contributor III

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.

0 Kudos
1 Solution

Accepted Solutions
JohannesBierer
Regular Contributor

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)

View solution in original post

2 Replies
JohannesBierer
Regular Contributor

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)
PaulGardiner
New Contributor III

Perfect, thanks for that Johannes. That works perfectly.

0 Kudos