Author Posts

January 5, 2017 at 4:17 pm

Friends,

I have many many files named like aaaaa.mxf I wish to have them named aaaaa.j2k.mxf
the aaaa in this example is a big long number that varies in length.

I have limited success with

Dir *.mxf | rename-item -newname { [io.path]::ChangeExtention($_.name, "j2k.mxf") }

my problem is These files go into a dir and I wish to update it daily
so – with the above solution
monday works fine but on tue the monday load gets aaaa.j2k.j2k.mxf etc etc.

so i need a IF or something that ...maybe uses -no_match

basically like
If instring is NOT already j2k.mxf
then
Dir *.mxf | rename-item -newname { [io.path]::ChangeExtention($_.name, "j2k.mxf") }

I have tried some things .... all so far off that I hesitate to mention.

thanks for help in advance.

I am just starting with powershell

thanks again

January 5, 2017 at 4:39 pm

You don't necessarily need an IF, you can just exclude files currently named with j2k.mxf. You should validate it's working as expected with -WhatIf and then you can remove it to actually make changes. Try something like this:

Get-ChildItem *.mxf | 
Where {$_.Name -notlike "*j2k.mxf"} |
Rename-Item -NewName ("{0}.j2k{1}" -f $_.BaseName, $_.Extension) -WhatIf

January 5, 2017 at 5:11 pm

Get-ChildItem \\path\to\files -Filter *.mxf -Exclude *.j2k.mxf -Recurse |
Rename-Item -NewName {$_.name -replace '\.mxf','.j2k.mxf'}

January 5, 2017 at 6:20 pm

Thanks Bro — the notion of a -WhatIf is intresting

I am happily working with
Get-ChildItem D:\0000\ -Filter *.mxf -Exclude *.j2k.mxf -Recurse |
Rename-Item -NewName {$_.name -replace '\.mxf','.j2k.mxf'}

much thanks to you both

January 6, 2017 at 3:31 pm

it seems that
Get-ChildItem *.mxf |
Where {$_.Name -notlike "*j2k.mxf"} |
Rename-Item -NewName ("{0}.j2k{1}" -f $_.BaseName, $_.Extension) -WhatIf

does not work

meaning
a file a.xmf will Not be renamed a.j2k.mxf but rather a.j2k

I have fooled around with it .... have not gotten it to work

January 6, 2017 at 4:57 pm

in D:\0000
i have 2 files a.mxf , b.j2k.mxf
goal : skip the already fixed b.j2k.mxf and Fix a.mxf to a.j2k.mxf

Get-ChildItem D:\0000\*.mxf |
Where {$_.Name -notlike "*j2k.mxf"} |
Rename-Item -NewName (".j2k.mxf" -f $_.BaseName, $_.Extension) -WhatIf

at if: Performing the operation "Rename File" on target "Item: D:\0000\a.mxf Destination: D:\0000\.j2k.mxf".

we are missing the basefilename