MSBUild: Copy files with a name based on the original (following a pattern)

前端 未结 4 1972
温柔的废话
温柔的废话 2021-02-12 23:39

I have a set of files inside a folder. They all have a name which matches the pattern DR__.*. I want to copy them to another folder, but removing the DR__ prefix. How can I do t

4条回答
  •  死守一世寂寞
    2021-02-13 00:25

    I agree with @Si's solution. But with MSBuild 4.0 you can do it with built in functionality. NAnt script is much clearer than mine. But I will add it as a solution just to show MSBuild 4.0 techniques:

        
           
        
    
        
             
                %(CVParameters.FileName)%(CVParameters.Extension)          
                DR__
                $(Prefix.Length)
                $(OriginalFileName.Length)
                $([MSBuild]::Subtract($(OriginalFileNameLength),$(PrefixLength)))
                $(OriginalFileName.Substring($(PrefixLength),$(SubstringLength)))
                $([System.IO.Path]::Combine($(DestinationDir),$(ModifiedFileName)))
                                                                                                                                                      
    
             
        
    

    Edit (by OP): To get this working, I had to replace $(DestinationFullPath)in Copy with @(DestinationFullPath), to match the number of Source and Destination Files. Also, I had to change the prefix to DR__, since DR__. wouldn't work.

提交回复
热议问题