Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

[solved] Renaming or truncation part of a file name

$
0
0

I know this gets beaten to death, but I can't find an example of what I'm trying to achieve.

Say I have a folder full of txt files named something like:

c:\tmp\john.1.2.3.abc8-test.txt

c:\tmp\sean.T2C3.abc8-something.txt

c:\tmp\billy.bob.S837.C3.abc8-whoknows.txt

 

I want to do a foreach statement on the directory and either remove "abc8", which they all have in common, + anything after it until the ".txt". If it's easier, I can keep the abc8, but I want to remove everything after it..no matter what is after it...but still keep the file extension of course.

So after I run the script it would look like:

c:\tmp\john.1.2.3.abc8.txt

c:\tmp\sean.T2C3.abc8.txt

c:\tmp\billy.bob.S837.C3.abc8.txt

Any suggestions? Thanks


Viewing all articles
Browse latest Browse all 6937

Trending Articles