How to trim part of a filename?


hello experts

one of computers got infected virus. changes name of many files to 

(!! password email id 1576391191 allsecinfo@gmail.com !!).exe

here of 1 pdf file has been renamed virus

risk management practices @ industrial facilities.pdf(!! password email id 1576391191 allsecinfo@gmail.com !!).exe

since not files pdf similarity on each of them  part after (!! ......... !!).exe.  how tell powershell trim part of file name?

thanks!!

this should work (it worked on 2 files me) :

$srcdir = "c:\temp" foreach ($file in (get-childitem $srcdir | ?{$_.name -match "^.*\(\!\!.*\!\!\)\..*?"})) {    rename-item $file.fullname ($file.name -replace "\(\!\!.*\!\!\)") } 

if files spread on entire hard drive, change "c:\temp" "c:\" , add -recurse after get-childitem command:

$srcdir = "c:\" foreach ($file in (get-childitem $srcdir -recurse | ?{$_.name -match "^.*\(\!\!.*\!\!\)\..*?"})) {    rename-item $file.fullname ($file.name -replace "\(\!\!.*\!\!\)") }

but note take time process patient.  it targeting file (!! !!) before extension, not entire string specified, haven't other files named similarly.


i hope post has helped!



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Round Robin is killing performance on our network

WMI Repository 4GB limit - Win 2003 Ent Question

Change home folder default permission?