![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Newbie Needs Help With Folder script! Hi All, I need to write a script that reads in a list of user directories from a text file, and renames any existing file to "usernameold", and then just copies them from one share to another. Basically I just want to rename \\oldserver\share\user1 to \\oldserver \share\user1old and then to copy in \\newserver\share\user1 to \ \oldserver\share\user1. and to repeat this for a number of folders in a text file. Any hints, or starting points would be greatly appreciated!! Cheers, M |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Newbie Needs Help With Folder script! You can make use of following cmdlet + some logic for your requirement #Check if the file exists or not Test-Path $FileName # Renames the file Rename-Item -path $OldFileName $NewFileName # Removes the file Remove-Item $File #Creates new directory New-Item -Path $Folder -Name $FolderName -Type directory -Force "Mícheál" <michael.halpin@gmail.com> wrote in message news:1176290895.915025.187920@o5g2000hsb.googlegroups.com... > Hi All, > > I need to write a script that reads in a list of user directories from > a text file, and renames any existing file to "usernameold", and then > just copies them from one share to another. > > Basically I just want to rename \\oldserver\share\user1 to \\oldserver > \share\user1old and then to copy in \\newserver\share\user1 to \ > \oldserver\share\user1. and to repeat this for a number of folders in > a text file. > > Any hints, or starting points would be greatly appreciated!! > > Cheers, > M > |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Newbie Needs Help With Folder script! On Apr 11, 12:28 pm, "Mícheál" <michael.hal...@gmail.com> wrote: > Hi All, > > I need to write a script that reads in a list of user directories from > a text file, and renames any existing file to "usernameold", and then > just copies them from one share to another. > > Basically I just want to rename \\oldserver\share\user1 to \\oldserver > \share\user1old and then to copy in \\newserver\share\user1 to \ > \oldserver\share\user1. and to repeat this for a number of folders in > a text file. > > Any hints, or starting points would be greatly appreciated!! > > Cheers, > M You could start by reading in the dir list and looping through each line, and then inside that loop, loop through each of files contained in each folder - something like this: untested - but should get you going... ($_ refers to the current item in the iteration) get-content dirlist.txt | foreach { gci $_ | foreach { cp $_.fullname "\\newserver\share\($_.name).old" } } |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Newbie Needs Help With Folder script! On Apr 11, 1:43 pm, "Duncan Smith" <DSmith1...@googlemail.com> wrote: > On Apr 11, 12:28 pm, "Mícheál" <michael.hal...@gmail.com> wrote: > > > Hi All, > > > I need to write a script that reads in a list of user directories from > > a text file, and renames any existing file to "usernameold", and then > > just copies them from one share to another. > > > Basically I just want to rename \\oldserver\share\user1 to \\oldserver > > \share\user1old and then to copy in \\newserver\share\user1 to \ > > \oldserver\share\user1. and to repeat this for a number of folders in > > a text file. > > > Any hints, or starting points would be greatly appreciated!! > > > Cheers, > > M > > You could start by reading in the dir list and looping through each > line, and then inside that loop, loop through each of files contained > in each folder - something like this: untested - but should get you > going... ($_ refers to the current item in the iteration) > > get-content dirlist.txt | foreach { > gci $_ | foreach { > cp $_.fullname "\\newserver\share\($_.name).old" > } > > } Thanks Duncan (and Nikhil), I'l work from that and post back what I come up with. Cheers!! M |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: Newbie Needs Help With Folder script! On Apr 11, 2:01 pm, "Mícheál" <michael.hal...@gmail.com> wrote: > On Apr 11, 1:43 pm, "Duncan Smith" <DSmith1...@googlemail.com> wrote: > > > > > On Apr 11, 12:28 pm, "Mícheál" <michael.hal...@gmail.com> wrote: > > > > Hi All, > > > > I need to write a script that reads in a list of user directories from > > > a text file, and renames any existing file to "usernameold", and then > > > just copies them from one share to another. > > > > Basically I just want to rename \\oldserver\share\user1 to \\oldserver > > > \share\user1old and then to copy in \\newserver\share\user1 to \ > > > \oldserver\share\user1. and to repeat this for a number of folders in > > > a text file. > > > > Any hints, or starting points would be greatly appreciated!! > > > > Cheers, > > > M > > > You could start by reading in the dir list and looping through each > > line, and then inside that loop, loop through each of files contained > > in each folder - something like this: untested - but should get you > > going... ($_ refers to the current item in the iteration) > > > get-content dirlist.txt | foreach { > > gci $_ | foreach { > > cp $_.fullname "\\newserver\share\($_.name).old" > > } > > > } > > Thanks Duncan (and Nikhil), > > I'l work from that and post back what I come up with. > > Cheers!! > M Hi Guys, in the end I didn't need to use it, but here's what I had and this bit worked (mostly!). The mv command wouldn't work unless both shares had the same root, I tried mapping drives to letters but still no joy. Anyway, the little bit of code at the start might help someone! $NewServer= "\\server2\test" $OldServer= "\\server1\scripts" gc c:\test\users.txt | Foreach-Object{ $folder = $_ echo "$folder" #just for debugging ren $folder $folder+old mv t:\$_ u:\ } |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Re: VB Script Code to get alert when a folder get changed in intranet FTP Folder | nageswara Rao | VB Script | 0 | 05-20-2008 05:06 AM |
| <newbie> question regarding the AppData folder | Jeff | Vista General | 2 | 02-13-2008 10:39 AM |
| Newbie question - Is there a script/command to do a backup of a di | dob | PowerShell | 4 | 01-03-2008 09:45 AM |
| Newbie Question: Here-Script with PowerShell | Raymund Hemmerling | PowerShell | 6 | 09-28-2007 03:34 AM |
| Newbie: running external script | bill | PowerShell | 3 | 12-22-2006 03:09 AM |