Reanming Files

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
juneb1022
Posts: 34
Joined: Mon Jun 10, 2013 10:14 am

Reanming Files

Post by juneb1022 » Mon Mar 24, 2014 10:32 am

I'm trying to find a doc or tutorial that explains how to rename files by adding a certain set word + the first 4 characters of that file.

E.G....

12341803.123 will be renamed Diners_1234_12341803.123

or

67891803.456 will be renamed Diners_6789_67891803.456

Any help is appreciated.

User avatar
jvierra
Posts: 13792
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Reanming Files

Post by jvierra » Mon Mar 24, 2014 10:51 am

This would be a good place to start: http://www.sapien.com/books/Windows-PowerShell-2

User avatar
juneb1022
Posts: 34
Joined: Mon Jun 10, 2013 10:14 am

Re: Reanming Files

Post by juneb1022 » Tue Mar 25, 2014 2:16 pm

Ok, I'm getting there.. :)


foreach ( $file in $files ) {
$str = Get-ChildItem "$Source\*.*" -Name
$str.Substring(0,4)
}

User avatar
jvierra
Posts: 13792
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Reanming Files

Post by jvierra » Tue Mar 25, 2014 2:51 pm

Try
Help rename-item -full

Locked