Answers.Body: <p>There is no good solution in Craft 2.x, but you probably can put together a plugin or a console app that does what you want it to do. Here's all the background info you, hopefully, need.</p>
  
  <p>The whole indexing process is controlled by javascript as well but let's just pretend you've instantiated the <code>AssetIndexTool</code> class and are operating on that via <code>performAction()</code></p>
  
  <p>Craft Asset indexer operates strictly on the data in <code>craft_assetindexdata</code> table. When you start an indexing task, the very first thing it does is query the Asset Sources for all the actual files that are there, stores a list of them in the said table and from that point on uses that table to reference what files have been indexed and which not. As it does it, Craft also creates all the folders already (because, apparently, a long time ago it seemed like a good idea to me).</p>
  
  <p>After that, the tool returns an array for each of the steps it needs to take, where one step is generated per file and also an additional "overview" step at the end. Each array entry basically contains parameters that you should throw back at the Index Tool.</p>
  
  <p>What you're interested in each of those "step" arrays (if you want to understand how the whole process works) is <code>sessionId</code> variable there to track the indexing session in the indexing table, the <code>sourceId</code> variable so you know which source you're operating on and the <code>offset</code> variable that tells the Index Tool which file in the indexing table to look up and actually index.</p>
  
  <p>You should definitely also follow through with the last overview step. Never mind that it presents the user with a HTML dialog for all the files that are in the DB but are not present in the source, but, more importantly, it cleans up the asset indexing table and removes the obsolete data in there.</p>
  
  <p>The great news is that it will be significantly less convoluted and way more accessible programmatically in Craft 3.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-02T20:57:43.343Z
Answers.Text: Thanks Andris. Glad to hear this will be improving in the future.
Answers.UserDisplayName: Ben Parizek
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-29T08:22:11.837Z
Answers.LastActivityDate: 2016-10-03T06:03:19.490Z
Answers.LastEditDate: 2016-10-03T06:03:19.490Z
Answers.UserDisplayName: Andris Sevcenko
Body: <p>I have a folder with 10GB of files that I need to sync with Craft. It has 12 subfolders, one for each year:</p>
  
  <pre><code>/1999
    /01
    /02
    /03
    /...
  </code></pre>
  
  <p>It's possible to run Update Asset Indexes on the top-level folder but this process takes several hours and can't be interrupted. If things get interrupted, for whatever reason, some of the sub-folders are successfully imported but the other subfolders aren't, and there is no simple way to pick things up where they left off without restarting the full process. Ouch.</p>
  
  <p>Is it possible to sync a specific asset subfolder, or list of subfolders? How would I approach this programmatically? </p>
  
  <p>It seems I may want to call the <code>AssetIndexTool::performAction</code> method but only pass in the subfolder IDs or something like that. I haven't interfaced with the Tool classes at all. Is this a reasonable direction to consider or am I not considering another potential direction?</p>
  
Tags: <assets><import>
Title: Is it possible to use Update Asset Indexes on a target subfolder or subfolders?
ThreadText: # Is it possible to use Update Asset Indexes on a target subfolder or subfolders?
  
  (Asked by: username_0 on 2016-09-28)
  
  I have a folder with 10GB of files that I need to sync with Craft. It has 12 subfolders, one for each year:
  
  ```
  /1999
    /01
    /02
    /03
    /...
  
  ```
  
  It's possible to run Update Asset Indexes on the top-level folder but this process takes several hours and can't be interrupted. If things get interrupted, for whatever reason, some of the sub-folders are successfully imported but the other subfolders aren't, and there is no simple way to pick things up where they left off without restarting the full process. Ouch.
  
  Is it possible to sync a specific asset subfolder, or list of subfolders? How would I approach this programmatically?
  
  It seems I may want to call the `AssetIndexTool::performAction` method but only pass in the subfolder IDs or something like that. I haven't interfaced with the Tool classes at all. Is this a reasonable direction to consider or am I not considering another potential direction?
  
  **Tags:** assets, import
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-09-29. Score: 3 | Accepted answer
  
  There is no good solution in Craft 2.x, but you probably can put together a plugin or a console app that does what you want it to do. Here's all the background info you, hopefully, need.
  
  The whole indexing process is controlled by javascript as well but let's just pretend you've instantiated the `AssetIndexTool` class and are operating on that via `performAction()`
  
  Craft Asset indexer operates strictly on the data in `craft_assetindexdata` table. When you start an indexing task, the very first thing it does is query the Asset Sources for all the actual files that are there, stores a list of them in the said table and from that point on uses that table to reference what files have been indexed and which not. As it does it, Craft also creates all the folders already (because, apparently, a long time ago it seemed like a good idea to me).
  
  After that, the tool returns an array for each of the steps it needs to take, where one step is generated per file and also an additional "overview" step at the end. Each array entry basically contains parameters that you should throw back at the Index Tool.
  
  What you're interested in each of those "step" arrays (if you want to understand how the whole process works) is `sessionId` variable there to track the indexing session in the indexing table, the `sourceId` variable so you know which source you're operating on and the `offset` variable that tells the Index Tool which file in the indexing table to look up and actually index.
  
  You should definitely also follow through with the last overview step. Never mind that it presents the user with a HTML dialog for all the files that are in the DB but are not present in the source, but, more importantly, it cleans up the asset indexing table and removes the obsolete data in there.
  
  The great news is that it will be significantly less convoluted and way more accessible programmatically in Craft 3.
  
  > **Comments:**
  > **username_0**: Thanks username_1. Glad to hear this will be improving in the future.  
  
  ---
  
  