AnsweredAssumed Answered

need method to split filenames for item titles in item add()

Question asked by jhead@lakeworth on May 16, 2018
Latest reply on May 17, 2018 by jhead@lakeworth

probably a newbie question but here goes:

 

I am adding a large number of PDF's to a newly created folder...

I am using glob.glob to grab all file paths into a list

I also need to use the data_properties dictionary to add the filename as the items title and not the entire path name.

 

code is below... everything works but its uploading the title as the full path name, i need to split the file path to only grab the files name for title.

(before you ask, if I don't use time.sleep the API will skip some items for the sharing between function calls.)

 

method to grab filenames within the for loop and assign to variable to use in the pdf_properties 'title'

 

import arcgis
from arcgis.gis import *
import os
import glob
import time

 

gis = GIS(None, "username", "password")
contentManager = arcgis.gis.ContentManager(gis)
contentManager.create_folder('new folder name,None)

 

pdf_list = glob.glob(r'C:\Users\username\Desktop\pdf\*.pdf')

 

additem = arcgis.gis.ContentManager(gis)

 

for pdf in pdf_list:
    pdf_properties = {'type':'PDF','title':pdf,'tags':'pdf, arcgis,lakeworth', 'access':'Public'}
    additem.add(pdf_properties,pdf,folder='Historic PDFs')
    time.sleep(1)
item_search = gis.content.search(query='', item_type='PDF')
item_search

for item in item_search:
    item.share(everyone=True)
    time.sleep(1)

Outcomes