Dela via


DeleteFiles@1 - Delete files v1 task

Delete files or folders. (The minimatch patterns will only match file paths, not folder paths).

Inputs

SourceFolder - Source Folder
string.

If the source folder is empty, the task deletes files from the root folder of the repository as though $(Build.SourcesDirectory) was specified. If your build produces artifacts outside of the sources directory, specify $(Agent.BuildDirectory) to delete files from the build agent working directory.


Contents - Contents
string. Required. Default value: myFileShare.

The file/folder paths to delete. Supports multiple lines of minimatch patterns; each one is processed before moving onto the next line. Learn more about File matching patterns. For example:

  • **/* deletes all files and folders in the root folder.
  • temp deletes the temp folder in the root folder.
  • temp* deletes any file or folder in the root folder with a name that begins with temp.
  • **/temp/* deletes all files and folders in any sub-folder named temp.
  • **/temp* deletes any file or folder with a name that begins with temp.
  • !(*.vsix) deletes all files in the root folder that do not have a .vsix extension.

Task control options

All tasks have control options in addition to their task inputs. For more information, see Control options and common task properties.

Output variables

None.

Remarks

Use this task to delete files or folders from the agent working directory.

Examples

Delete several patterns

This example will delete some/file, all files beginning with test, and all files in all subdirectories called bin.

steps:
- task: DeleteFiles@1
  displayName: 'Remove unneeded files'
  inputs:
    contents: |
      some/file
      test*
      **/bin/*

Delete all but one subdirectory

This example will delete some/one, some/three and some/four but will leavesome/two.

steps:
- task: DeleteFiles@1
  displayName: 'Remove unneeded files'
  inputs:
    contents: |
      some/!(two)

Delete using brace expansion

This example will delete some/one and some/four but will leave some/two and some/three.

steps:
- task: DeleteFiles@1
  displayName: 'Remove unneeded files'
  inputs:
    contents: |
      some/{one,four}

Delete files starting with a dot

This example will delete all .txt files. Files starting with a dot will be deleted as well.

steps:
- task: DeleteFiles@1
  displayName: 'Remove unneeded files'
  inputs:
    contents: |
      /some/*.txt
    removeDotFiles: true

Requirements

Requirement Description
Pipeline types YAML, Classic build
Runs on Agent, DeploymentGroup
Demands None
Capabilities This task does not satisfy any demands for subsequent tasks in the job.
Command restrictions Any
Settable variables Any
Agent version 1.92.0 or greater
Task category Utility