Hello,
I'd like to check if a folder exists in the portal before I create it. I don't see the feature_type = 'folder' option.
Thank you in advance,
Marcelo
You can user the folder property of a user. I've created an example, where I'm using my own user. I create a list with the titles of the folders, that I currently have in my content. If a folder with a given name is not found, it will be created
gis <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN>portalURL<SPAN class="punctuation token">,</SPAN> username<SPAN class="punctuation token">,</SPAN> password<SPAN class="punctuation token">)</SPAN> me <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>users<SPAN class="punctuation token">.</SPAN>me my_folders <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>me<SPAN class="punctuation token">.</SPAN>folders<SPAN class="punctuation token">)</SPAN> new_folder <SPAN class="operator token">=</SPAN> <SPAN class="string token">'my new folder'</SPAN> folder_list <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'title'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> my_folders<SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">if</SPAN> new_folder <SPAN class="operator token">not</SPAN> <SPAN class="keyword token">in</SPAN> folder_list<SPAN class="punctuation token">:</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>create_folder<SPAN class="punctuation token">(</SPAN>new_folder<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
However, it is worth noting that create_folder does nothing, if the folder already exists.
Link to api-reference
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.