Say for example, you are selecting a bunch of files as follows:
<CreateItem Include="C:\MyFolder\**\*"> <Output ItemName="AllFiles" TaskParameter="Include"/> </CreateItem>
In this case, we are searching a folder called C:\MyFolder, and if we have a sub-folder called MySubDir containing a file called MyFile.txt, then the metadata items are:
|Identity||Value for the item specified in the Include attribute.||C:\MyFolder\MySubDir\MyFile.txt|
|Filename||Filename for this item, not including the extension.||MyFile|
|Extension||File extension for this item.||.txt|
|FullPath||Full path of this item including the filename.||C:\MyFolder\MySubDir\MyFile.txt|
|RelativeDir||Path to this item relative to the current working directory.||C:\MyFolder\MySubDir\|
|RootDir||Root directory to which this item belongs.||C:\|
|RecursiveDir||Used for items that were created using wildcards. This would be the directory that replaces the wildcard(s) statements that determine the directory.||MySubDir\|
|Directory||The directory of this item. Notice that the Drive is not specified.||MyFolder\MySubDir\|
|AccessedTime||Last time this item was accessed.||2009-05-22 10:29:47.3567776|
|CreatedTime||Time the item was created.||2009-05-22 10:29:47.3567776|
|ModifiedTime||Time this item was modified.||2009-05-22 10:29:47.3567776|
You can refernce any of these metadata in your MSBuild script using the syntax %(AllFiles.Blah), substituting the 'Blah' for the metadata you need.
The wildcards available are: * - Match 0 or many characters. ** - Recursively search all sub-folders. ? - Match a single character.
Deleting sub-folders, but not files
So, as an example, today I needed to delete all of the sub-folders in a folder, but not the files. Here's the MSBuild — making sure to Exclude the files using the Exclude attribute:
<!-- Remove the sub-folders of MyFolder --> <CreateItem Include="C:\MyFolder\**\*" Exclude="C:\MyFolder\*"> <Output ItemName="AllSubDirs" TaskParameter="Include"/> </CreateItem> <Message Text="Removing sub-folders..." /> <RemoveDir Directories="%(AllSubDirs.RootDir)%(AllSubDirs.Directory)" />
This post can also be found on my personal blog.