<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: need method to split filenames for item titles in item add() in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/need-method-to-split-filenames-for-item-titles-in/m-p/783982#M1317</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A class="link-titled" href="https://docs.python.org/3/library/os.path.html" title="https://docs.python.org/3/library/os.path.html"&gt;11.2. os.path — Common pathname manipulations — Python 3.6.5 documentation&lt;/A&gt; , see split or basename&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;pdf_name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;basename&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;pdf&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 16 May 2018 21:30:31 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2018-05-16T21:30:31Z</dc:date>
    <item>
      <title>need method to split filenames for item titles in item add()</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/need-method-to-split-filenames-for-item-titles-in/m-p/783981#M1316</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;probably a newbie question but here goes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am adding a large number of PDF's to a newly created folder...&lt;/P&gt;&lt;P&gt;I am using glob.glob to grab all file paths into a list&lt;/P&gt;&lt;P&gt;I also need to use the data_properties dictionary to add the filename as the items title and not the entire path name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;(before you ask, if I don't use time.sleep the API will skip some items for the sharing between function calls.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;method to grab filenames within the for loop and assign to variable to use in the pdf_properties 'title'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;import arcgis&lt;BR /&gt;from arcgis.gis import *&lt;BR /&gt;import os&lt;BR /&gt;import glob&lt;BR /&gt;import time&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;gis = GIS(None, "username", "password")&lt;BR /&gt;contentManager = arcgis.gis.ContentManager(gis)&lt;BR /&gt;contentManager.create_folder('new folder name,None)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;pdf_list = glob.glob(r'C:\Users\username\Desktop\pdf\*.pdf')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;additem = arcgis.gis.ContentManager(gis)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for pdf in pdf_list:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pdf_properties = {'type':'PDF','title':pdf,'tags':'pdf, arcgis,lakeworth', 'access':'Public'}&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; additem.add(pdf_properties,pdf,folder='Historic PDFs')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; time.sleep(1) &lt;BR /&gt;item_search = gis.content.search(query='', item_type='PDF')&lt;BR /&gt;item_search&lt;/P&gt;&lt;P&gt;for item in item_search:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; item.share(everyone=True)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; time.sleep(1)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 May 2018 20:53:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/need-method-to-split-filenames-for-item-titles-in/m-p/783981#M1316</guid>
      <dc:creator>Lake_Worth_BeachAdmin</dc:creator>
      <dc:date>2018-05-16T20:53:31Z</dc:date>
    </item>
    <item>
      <title>Re: need method to split filenames for item titles in item add()</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/need-method-to-split-filenames-for-item-titles-in/m-p/783982#M1317</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A class="link-titled" href="https://docs.python.org/3/library/os.path.html" title="https://docs.python.org/3/library/os.path.html"&gt;11.2. os.path — Common pathname manipulations — Python 3.6.5 documentation&lt;/A&gt; , see split or basename&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;pdf_name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;basename&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;pdf&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 May 2018 21:30:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/need-method-to-split-filenames-for-item-titles-in/m-p/783982#M1317</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-05-16T21:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: need method to split filenames for item titles in item add()</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/need-method-to-split-filenames-for-item-titles-in/m-p/783983#M1318</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;yes I got the answer on stackoverflow but this still appends the ".pdf" suffix&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was able to use&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;pdf_name.split(".")[0]&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;to get the desired results&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 May 2018 22:51:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/need-method-to-split-filenames-for-item-titles-in/m-p/783983#M1318</guid>
      <dc:creator>Lake_Worth_BeachAdmin</dc:creator>
      <dc:date>2018-05-16T22:51:26Z</dc:date>
    </item>
    <item>
      <title>Re: need method to split filenames for item titles in item add()</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/need-method-to-split-filenames-for-item-titles-in/m-p/783984#M1319</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You might want to use &lt;SPAN style="font-family: courier\ new, courier, monospace;"&gt;os.path.splitext()&lt;/SPAN&gt;, just in case a PDF file name has a period in it, which is allowed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 May 2018 23:17:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/need-method-to-split-filenames-for-item-titles-in/m-p/783984#M1319</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-05-16T23:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: need method to split filenames for item titles in item add()</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/need-method-to-split-filenames-for-item-titles-in/m-p/783985#M1320</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;all the pdf names will integers (parcel control numbers) but thanks for the info it will be helpful with other projects &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 May 2018 12:02:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/need-method-to-split-filenames-for-item-titles-in/m-p/783985#M1320</guid>
      <dc:creator>Lake_Worth_BeachAdmin</dc:creator>
      <dc:date>2018-05-17T12:02:52Z</dc:date>
    </item>
  </channel>
</rss>

