I have a lot of windows files where the filename contains a %. See below:
c:\temp>
dir /b
114902_T%3A%5CAccounting%5CPayables%5CAPA%5CBoshart Apr 25%5CBII_inv_1489879.pdf
114904_T%3A%5CAccounting%5CPayables%5CAPA%5CBoshart Apr 25%5CBII_inv_1489880.pdf
114906_T%3A%5CAccounting%5CPayables%5CAPA%5CBoshart Apr 25%5CBII_inv_1491058.pdf
114916_T%3A%5CAccounting%5CPayables%5CAPA%5CBoshart Apr 25%5CBII_inv_1491059.pdf
114918_T%3A%5CAccounting%5CPayables%5CAPA%5CBoshart Apr 25%5CBII_inv_1491452.pdf
114920_T%3A%5CAccounting%5CPayables%5CAPA%5CBoshart Apr 25%5CBII_inv_1491453.pdf
114923_T%3A%5CAccounting%5CPayables%5CAPA%5CBoshart Apr 25%5CBII_inv_1491454.pdf
115513_T%3A%5CAccounting%5CPayables%5CAPA%5CABB MAY 15%5C0039292647.pdf
115515_T%3A%5CAccounting%5CPayables%5CAPA%5CABB MAY 15%5C0039295860.pdf
115517_T%3A%5CAccounting%5CPayables%5CAPA%5CABB MAY 15%5C0039296218.pdf
115523_T%3A%5CAccounting%5CPayables%5CAPA%5CABB MAY 15%5C0039308592.pdf
115525_T%3A%5CAccounting%5CPayables%5CAPA%5CABB MAY 15%5C0039308593.pdf
120342_T%3A%5CAccounting%5CPayables%5CAPA%5CABB MAY 15%5C0039328905.pdf
120345_T%3A%5CAccounting%5CPayables%5CAPA%5CABB MAY 15%5C0039337204.pdf
120348_T%3A%5CAccounting%5CPayables%5CAPA%5CABB MAY 15%5C0039337221.pdf
120351_T%3A%5CAccounting%5CPayables%5CAPA%5CABB MAY 15%5C0039337461.pdf
120639_T%3A%5CAccounting%5CPayables%5CAPA%5CAFA MAY 15%5CINV#63168731.pdf
120640_T%3A%5CAccounting%5CPayables%5CAPA%5CAFA MAY 15%5CINV#63168988.pdf
120642_T%3A%5CAccounting%5CPayables%5CAPA%5CAFA MAY 15%5CINV#63168993.pdf
120644_T%3A%5CAccounting%5CPayables%5CAPA%5CAFA MAY 15%5CINV#63169027.pdf
These % are actually hex code for a : (%3A) and \ (%5C). I can't explain how they got this way when they were copied from another system, but this what I have to work with. For clarity, this is what is looks like with the hex code.
114902_T:\Accounting\Payables\APA\Boshart Apr 25\BII_inv_1489879.pdf
What I want to do is to rename the file from this:
114902_T%3A%5CAccounting%5CPayables%5CAPA%5CBoshart Apr 25%5CBII_inv_1489879.pdf
to this:
BII_inv_1489879.pdf
I tried following other rename exmaples to use the % as a delimiter, but what further complicates things is the last delimiter (the pdf filename) isn't always the 7th token.
Any help would be greatly appricitated.
^%
instead of%
in each of those places. Alternatively, if you happen to be familiar with Bash, you may want to (ab)use the Bash shell and basic set of tools that comes with Git for Windows. Personally I'm not a fan of Git (in particular because it makes assumptions about how unixoid a system ought to be), but in this case you can make it work to your advantage.114902_T%3A%5CAccounting%5CPayables%5CAPA%5CBoshart Apr 25%5CBII_inv_1489879.pdf
toBII_inv_1489879.pdf
by typingren "114902_T%3A%5CAccounting%5CPayables%5CAPA%5CBoshart Apr 25%5CBII_inv_1489879.pdf" "BII_inv_1489879.pdf"
. (The quotes aroundBII_inv_1489879.pdf
are optional.) If you want a more general solution, please describe what you want, and provide a wider range of examples. … (Cont’d)%nn
always be a%5C
? If not, do you want the filename to be cut after the last%nn
or after the last%5C
? Will there ever be%
characters in the filename that are not part of a%nn
sequence? Are there any other characters in the filenames that are likely to be problematic for scripting? Etc.