![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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 | renaming and moving files all together Hi guys. Once again I need your help to solve a problem. Let's say that in my H unit I have a serie of files without extension like this myserie1 myserie2 myserie3 and so on. I'd like to find within my folder all the files that start with myserie, add avi extension and finally move them to unit C inside another folder. I've solved with two separate commands in this way gci | ? {$_.name.startswith("myserie")} | % {rename-item $_ ($_.name +".avi")} gci | ? {$_.name.startswith("myserie")} | % {move-item $_ -dest c:\serie} but I'd like to know if it's possible to use just one line of code I've tried in this way but files are renamed but they're not copied. gci | ? {$_.name.startswith("myserie")} | % {rename-item $_ ($_.name +".avi")} | % {copy-item $_.name c:\serie} Is there a solution? Thanks. |
My System Specs![]() |
| | #2 (permalink) |
| | RE: renaming and moving files all together # rename them as you move them ls h:\serie myserie* | ? {$_.name -match '\d+$'} | mi -des {'c:\serie\' + $_.name + '.avi'} -- Kiron |
My System Specs![]() |
| | #3 (permalink) |
| Vista Home Premium 32bit | Re: renaming and moving files all together It's perfect Kiron, thanks. ![]() However I don't understand why it works without using foreach before mi. |
My System Specs![]() |
| | #4 (permalink) |
| | Re: renaming and moving files all together On Aug 5, 12:59*am, sardinian_guy <gu...@xxxxxx-email.com> wrote: Quote: > It's perfect Kiron, thanks. ![]() > > However I don't understand why it works without using foreach before > mi. ![]() > > -- > sardinian_guy loops through them. From the documentation: -------------------------- EXAMPLE 4 -------------------------- C:\PS>get-childitem -path . -recurse -include *.txt | move-item - destination C:\TextFiles This command moves all of the text files from the current directory and all subdirectories, recursively, to the C:\TextFiles directory. The command uses the Get-Childitem cmdlet to get all of the child items in the current directory (represented by the dot (.)) and its subdirectories that have a *.txt file name extension. It uses the Recurse parameter to make the retrieval recursive and the Include parameter to limit the retrieval to *.txt files. The pipeline operator (|) sends the results of this command to Move- Item, which moves the text files to the TextFiles directory. If files being moved to C:\Textfiles have the same name, Move-Item displays an error and continues, but moves only one file with each name to C:\Textfiles. The other files remain in their original directories. If the Textfiles directory (or any other element of the destination path) does not exist, the command fails. The missing directory is not created for you, even if you use the Force parameter. Move-Item moves the first item to a file called "Textfiles" and then displays an error explaining that the file already exists. Also, by default, Get-Childitem does not move hidden files. To move hidden files, use the Force parameter with Get-Childitem. |
My System Specs![]() |
| | #5 (permalink) |
| | Re: renaming and moving files all together It is a pretty cool feature, Jeffrey Snover explains it in the PS Team's blog: http://blogs.msdn.com/powershell/arc...23/643674.aspx http://blogs.msdn.com/powershell/arc...arameters.aspx -- Kiron |
My System Specs![]() |
| | #6 (permalink) |
| Vista Home Premium 32bit | Re: renaming and moving files all together Thank you very much to both. ![]() I don't understand why under my nickname there is that image. I'm a newbie, not a skilled one. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Renaming/moving Folders and/or files | Vista General | |||
| Moving, Deleting and Renaming within Vista | Vista hardware & devices | |||
| Renaming Files: Can I Prevent Explorer From Moving to Where the Renamed File Is? | Vista file management | |||
| Re: huge lag on renaming/moving files in Vista | Vista General | |||
| Re: huge lag on renaming/moving files in Vista | Vista General | |||