![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| Vista Home Premium 32bit | rename-item, move-item and special chars. Unluckily another problem has risen. ![]() Within my nested folders may occur that different files have the same name. c:\my_path\file[].doc c:\my_path\folder1\file[].doc c:\my_path\folder2\file[].doc and so on. I need to move all these files to the same folder. To ensure that each file has a unique name I wrote this $i = 1 get-ChildItem -recurse -filter *.doc | % { rename-Item $_.fullname -newname ($i.ToString()+"#"+$_.name) $i++ } but obviously it doesn't work with special chars like "[" and "]". I've already read similar thread on this forum and I know that rename-item doesn't have -literalpath switch while move-item has it. How can I move those files to same folder giving them names like 1#file[].doc, 2#file[].doc, 3#file[].doc and so on. Thanks again. |
My System Specs![]() |
| | #2 (permalink) |
| Vista Home Premium 32bit | Re: rename-item, move-item and special chars. Unluckily another problem has risen. ![]() Within my nested folders may occur that different files have the same name. c:\my_path\file[].doc c:\my_path\folder1\file[].doc c:\my_path\folder2\file[].doc and so on. I need to move all these files to the same folder. To ensure that each file has a unique name I wrote this $i = 1 get-ChildItem -recurse -filter *.doc | % { rename-Item $_.fullname -newname ($i.ToString()+"#"+$_.name) $i++ } but obviously it doesn't work with special chars like "[" and "]". I've already read similar thread on this forum and I know that rename-item doesn't have -literalpath switch while move-item has it. How can I move those files to same folder giving them names like 1#file[].doc, 2#file[].doc, 3#file[].doc and so on. Thanks again. ![]() http://www.microsoft.com/communities...&sloc=&m=1&p=1 I wrote $i = 1 get-ChildItem -recurse -filter *.doc | % { move-Item -literalpath $_.fullname -destination ($_.directoryname+"\"+$i.ToString()+"#"+$_.name) -whatif $i++ } and it seems to work well. I can now write my paths to a txt file and move files with unique names to the same folders. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: rename-item, move-item and special chars. This is a bug Rename-Item does not take wildcards so doesn't need the LiteralPath rename-item file.doc file[].doc ## works just fine so the recepical rename-item file[].doc file.doc ## should work I suspect that Rename-Item is calling the equivalent of Get-Item passing the path qualifying it to be used as a literal path. "sardinian_guy" wrote: Quote: > > sardinian_guy;1099209 Wrote: Quote: > > Unluckily another problem has risen. ![]() > > Within my nested folders may occur that different files have the same > > name. > > > > c:\my_path\file[].doc > > c:\my_path\folder1\file[].doc > > c:\my_path\folder2\file[].doc > > > > and so on. > > > > I need to move all these files to the same folder. To ensure that each > > file has a unique name I wrote this > > > > $i = 1 > > get-ChildItem -recurse -filter *.doc | % { > > rename-Item $_.fullname -newname ($i.ToString()+"#"+$_.name) > > $i++ > > } > > > > but obviously it doesn't work with special chars like "[" and "]". > > I've already read similar thread on this forum and I know that > > rename-item doesn't have -literalpath switch while move-item has it. > > How can I move those files to same folder giving them names like > > > > 1#file[].doc, 2#file[].doc, 3#file[].doc and so on. Thanks again. ![]() > Ok, I've found this link > > http://www.microsoft.com/communities...&sloc=&m=1&p=1 > > I wrote > > $i = 1 > get-ChildItem -recurse -filter *.doc | % { > move-Item -literalpath $_.fullname -destination > ($_.directoryname+"\"+$i.ToString()+"#"+$_.name) -whatif > $i++ > } > > and it seems to work well. I can now write my paths to a txt file and > move files with unique names to the same folders. ![]() > > > -- > sardinian_guy > |
My System Specs![]() |
| | #4 (permalink) |
| Vista Home Premium 32bit | Re: rename-item, move-item and special chars. This is a bug Rename-Item does not take wildcards so doesn't need the LiteralPath rename-item file.doc file[].doc ## works just fine so the recepical rename-item file[].doc file.doc ## should work I suspect that Rename-Item is calling the equivalent of Get-Item passing the path qualifying it to be used as a literal path. "sardinian_guy" wrote: Quote: > > sardinian_guy;1099209 Wrote: Quote: > > Unluckily another problem has risen. ![]() > > Within my nested folders may occur that different files have the same > > name. > > > > c:\my_path\file[].doc > > c:\my_path\folder1\file[].doc > > c:\my_path\folder2\file[].doc > > > > and so on. > > > > I need to move all these files to the same folder. To ensure that each > > file has a unique name I wrote this > > > > $i = 1 > > get-ChildItem -recurse -filter *.doc | % { > > rename-Item $_.fullname -newname ($i.ToString()+"#"+$_.name) > > $i++ > > } > > > > but obviously it doesn't work with special chars like "[" and "]". > > I've already read similar thread on this forum and I know that > > rename-item doesn't have -literalpath switch while move-item has it. > > How can I move those files to same folder giving them names like > > > > 1#file[].doc, 2#file[].doc, 3#file[].doc and so on. Thanks again. ![]() > Ok, I've found this link > > Replace special characters in filenames - how? in Windows Powershell > > I wrote > > $i = 1 > get-ChildItem -recurse -filter *.doc | % { > move-Item -literalpath $_.fullname -destination > ($_.directoryname+"\"+$i.ToString()+"#"+$_.name) -whatif > $i++ > } > > and it seems to work well. I can now write my paths to a txt file and > move files with unique names to the same folders. ![]() > > > -- > sardinian_guy > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| rename-item problem | PowerShell | |||
| Invoke-Item cannot find paths with special characters | PowerShell | |||
| Rename-Item problem | PowerShell | |||
| Conflicting behaviour of rename-item cmdlet | PowerShell | |||
| Rename-Item bug? | PowerShell | |||