Question: I have the following hash table.

```
$m = @{
    "AAA" = "XX";
    "BBB" = "YY";
    "CCC" = "ZZ";
    ....
}

```

I want to rename the files which names started with "AAA" to "XX....", "BBB" to "YY....", etc. 
For example, "AAA1234.txt" will be renamed to "XX1234.txt".

How to do it in Powershell?

Answer: 
This code works for me:

```
$m = @{"AAA" = "XX"; "BBB" = "YY"}
$files = gci *.txt
$m.GetEnumerator() | % {
    $entry = $_ # save hash table entry for later use
    $files | ? { $_.Name.StartsWith($entry.Key) } | 
        % {
            $trimmed = $_.Name.Substring($entry.Key.length) # chops only the first occurence
            $newName = $entry.Value + $trimmed
            $_ | Rename-Item -NewName $newName        
        }        
}

```
Great..clearly explained.But this will rename the full folder name.. straight forward.

```
$m = @{"AA" = "XX"; "BB" = "YY"}
$files = Get-ChildItem -Path C:\test\ -Directory
$m.GetEnumerator() | %{Rename-Item "C:\test\$($_.Key)" -NewName "C:\test\$($_.value)" -Force
}

```