Princy
Princy

Reputation: 633

Renaming a Directory with wildcard on Powershell?

I have a folder that needs to be renamed.

$home/dir1/dir_to_rename_12344343

$value=abcd-1234

I know the beginning pattern of the folder but not the whole name.

I was trying to do something like this

cd $home/dir1

Rename-Item 'dir_to_rename*' '$value'

but it keeps giving me an error.

I am also happy if I can just trim the last few chars of the folder name.

i.e., $home/dir1/dir_to_rename_12344343 --> $home/dir1/dir_to_rename

Upvotes: -2

Views: 98

Answers (1)

Princy
Princy

Reputation: 633

I was finally able to get it to work

Get-ChildItem -Path $home/dir1 | Rename-Item -NewName $Value

Upvotes: 0

Related Questions