Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Windows 7 Forum Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

copying files referenced in an array...help?

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 02-28-2008   #1 (permalink)
greatbarrier86
Guest


 

copying files referenced in an array...help?

How would i create an array with a list of files in it, then have those files
copied to a specific location? would you use a ForEach statement?

Also, how would i set it up so i wouldnt have to state the full path for
each file? I'd like to be able to do $arrayname= file1, file2 instead of
$arrayname= C:\users\jason\desktop\files\file1...etc.

My System SpecsSystem Spec
Old 02-28-2008   #2 (permalink)
Shay Levi
Guest


 

Re: copying files referenced in an array...help?

If all files share a common *root* directory (user desktop) then you can
specify only the relative part, otherwise use full paths:

$files = "file1.txt","file2.txt","file3.txt"
$files | copy-item -path {"$env:userprofile\desktop\$_"} -dest c:\temp


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> How would i create an array with a list of files in it, then have
> those files copied to a specific location? would you use a ForEach
> statement?
>
> Also, how would i set it up so i wouldnt have to state the full path
> for each file? I'd like to be able to do $arrayname= file1, file2
> instead of $arrayname= C:\users\jason\desktop\files\file1...etc.
>

My System SpecsSystem Spec
Old 02-28-2008   #3 (permalink)
Shay Levi
Guest


 

Re: copying files referenced in an array...help?



btw... if you use full file paths then no piping is required since -path
is a string[] array:

$files = "C:\users\jason\desktop\files\file1.txt","C:\users\jason\desktop\files\file2.txt"
copy-item -path $files -dest c:\temp


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> If all files share a common *root* directory (user desktop) then you
> can specify only the relative part, otherwise use full paths:
>
> $files = "file1.txt","file2.txt","file3.txt"
> $files | copy-item -path {"$env:userprofile\desktop\$_"} -dest
> c:\temp
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
Quote:

>> How would i create an array with a list of files in it, then have
>> those files copied to a specific location? would you use a ForEach
>> statement?
>>
>> Also, how would i set it up so i wouldnt have to state the full path
>> for each file? I'd like to be able to do $arrayname= file1, file2
>> instead of $arrayname= C:\users\jason\desktop\files\file1...etc.
>>

My System SpecsSystem Spec
Old 02-28-2008   #4 (permalink)
greatbarrier86
Guest


 

Re: copying files referenced in an array...help?

Can you explain the second line? especially the $_

"Shay Levi" wrote:
Quote:

> If all files share a common *root* directory (user desktop) then you can
> specify only the relative part, otherwise use full paths:
>
> $files = "file1.txt","file2.txt","file3.txt"
> $files | copy-item -path {"$env:userprofile\desktop\$_"} -dest c:\temp
>
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

> > How would i create an array with a list of files in it, then have
> > those files copied to a specific location? would you use a ForEach
> > statement?
> >
> > Also, how would i set it up so i wouldnt have to state the full path
> > for each file? I'd like to be able to do $arrayname= file1, file2
> > instead of $arrayname= C:\users\jason\desktop\files\file1...etc.
> >
>
>
>
My System SpecsSystem Spec
Old 02-29-2008   #5 (permalink)
Shay Levi
Guest


 

Re: copying files referenced in an array...help?


Copy-Item's -Path parameter allows strings to be piped into it which means
that scriptblock parameters apply.
This way you can manipulate the piped string via $_.


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Can you explain the second line? especially the $_
>
> "Shay Levi" wrote:
>
Quote:

>> If all files share a common *root* directory (user desktop) then you
>> can specify only the relative part, otherwise use full paths:
>>
>> $files = "file1.txt","file2.txt","file3.txt"
>> $files | copy-item -path {"$env:userprofile\desktop\$_"} -dest
>> c:\temp
>> -----
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
Quote:

>>> How would i create an array with a list of files in it, then have
>>> those files copied to a specific location? would you use a ForEach
>>> statement?
>>>
>>> Also, how would i set it up so i wouldnt have to state the full path
>>> for each file? I'd like to be able to do $arrayname= file1, file2
>>> instead of $arrayname= C:\users\jason\desktop\files\file1...etc.
>>>

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying an array and weird things about updating arrays... bruce1313 PowerShell 7 08-03-2008 10:57 PM
Newbie question - Copying files listed in an array greatbarrier86 PowerShell 5 02-20-2008 04:03 PM
Copying files to Program Files directory Parrot Vista file management 13 08-23-2007 01:14 AM
how to assign values to array and how to create array via variable Frank PowerShell 1 03-13-2007 05:18 PM
Copying what files? Navdeep Singh Vista installation & setup 2 06-09-2006 12:34 PM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51