Answers.Body: <p>I found the solution: The moveFiles function provide the function to move a file:</p>
  
  <pre><code>/**
  * Move or rename files.
  *
  * @param        $fileIds
  * @param        $folderId
  * @param string $filename If this is a rename operation or not.
  * @param array  $actions  Actions to take in case of a conflict.
  *
  * @throws Exception
  * @return bool|AssetOperationResponseModel
  */
  
  public function moveFiles($fileIds, $folderId, $filename = '', $actions = array())
  </code></pre>
  
  <p>So for me the following code works to move the file with the id 21 to the folder with the id 3: </p>
  
  <pre><code>craft()-&gt;assets-&gt;moveFiles([21], 3,'', "keepBoth");
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-17T07:08:50.160Z
Answers.Text: Thanks for sharing! I kept getting an `Undefined offset: 1` error when moving multiple files though. So if you try this, remember to make `$actions` an array with the same length as `$fileIds`.
  
  Like this: `craft()->assets->moveFiles([21, 22], 3,'', ['keepBoth', 'keepBoth']);`
Answers.UserDisplayName: medoingthings
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-17T08:33:45.813Z
Answers.LastActivityDate: 2016-06-17T08:33:45.813Z
Answers.UserDisplayName: Tom Bauer
Body: <p>I would like to create a plugin/function to move all unused assets (which are not related to a entry) to a specific folder in the same assets source. Now i try to create the function to move a single file by referring the id of the file. But i get always errors... The function should look like this:</p>
  
  <pre><code>public function moveFileToFolder($fileId,$idOfTargetFolder,$assetSourceId) {
   ....
  }
  </code></pre>
  
  <p>Thanks for any help!</p>
  
Tags: <assets><plugins>
Title: Move unused Assets to a specific Folder
ThreadText: # Move unused Assets to a specific Folder
  
  (Asked by: username_0 on 2016-06-13)
  
  I would like to create a plugin/function to move all unused assets (which are not related to a entry) to a specific folder in the same assets source. Now i try to create the function to move a single file by referring the id of the file. But i get always errors... The function should look like this:
  
  ```
  public function moveFileToFolder($fileId,$idOfTargetFolder,$assetSourceId) {
   ....
  }
  
  ```
  
  Thanks for any help!
  
  **Tags:** assets, plugins
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-06-17. Score: 5
  
  I found the solution: The moveFiles function provide the function to move a file:
  
  ```
  /**
  * Move or rename files.
  *
  * @param        $fileIds
  * @param        $folderId
  * @param string $filename If this is a rename operation or not.
  * @param array  $actions  Actions to take in case of a conflict.
  *
  * @throws Exception
  * @return bool|AssetOperationResponseModel
  */
  
  public function moveFiles($fileIds, $folderId, $filename = '', $actions = array())
  
  ```
  
  So for me the following code works to move the file with the id 21 to the folder with the id 3:
  
  ```
  craft()->assets->moveFiles([21], 3,'', "keepBoth");
  
  ```
  
  > **Comments:**
  > **username_1**: Thanks for sharing! I kept getting an `Undefined offset: 1` error when moving multiple files though. So if you try this, remember to make `$actions` an array with the same length as `$fileIds`.  Like this: `craft()->assets->moveFiles([21, 22], 3,'', ['keepBoth', 'keepBoth']);`  
  
  ---
  
  