Thursday, 15 March 2012

Powershell renaming files containing repeating pattern (that has to be removed for the first occurrence) -


I would like to rename a group of files that can be repeated within the file name. To remove everything from the "dot + space" pattern at the beginning Ex: "wxxdv xcvxcv .sdfsdf .sd.txt" to create "sdfsdf.sd.txt" ("wxxdv xcvxcv."), Which removes the first occurrence of "dot + space" = "." ) East: "Rand M., Bilu. Arrival 1901.txt " " Arrival 1901.txt " ( Delete "should be M. , Bilu. ")

I found that the following commands are not too far from my goal (but does not work):

  dir * .txt | Mean-Dest {($ _ Basename -replace '^ [AG] + \.' S ',' '). Trim () + $ _ Extension}   

Bonus question,

Thanks, it is an attempt to use my first powers

  $ t = "round m, bill. Arrival 1901.txt" $ formatedText = $ t.Substring (([regex] :: split ($ t , '\. \ S') [0]). Length + 2) write-host $ formatedText arrival 1901.txt    

No comments:

Post a Comment