2021年3月31日星期三

powershell compare file names and rename

I have two directories with files in both of them. File count is different but file names are somewhat equal. For example:

C:\dwg   AR-01-12 - file name0.dwg  AR-01-13 - file name1.dwg  AR-01-14 - file name2.dwg    C:\pdf   AR-01-11 - file name_.pdf  AR-01-12-R1 - file name0.pdf  AR-01-13 - file name1.pdf  AR-01-14-R5 - file name2.pdf  AR-01-15-R4 - file name3.pdf  

Using powershell, how to rename files in C:\dwg folder so that they have this R abbreviation (from Revision) suffix added to name from file names in C:\pdf folder ? The result would be:

C:\dwg   AR-01-12-R1 - file name0.dwg  AR-01-13 - file name1.dwg  AR-01-14-R5 - file name2.dwg  

My logic would be to check if the first part of the filename is in the pdf directory, if it exists rename file, leaving the extencion.

https://stackoverflow.com/questions/66886890/powershell-compare-file-names-and-rename March 31, 2021 at 07:24PM

没有评论:

发表评论