Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.


Go Back   Vista Forums > Misc Newsgroups > PowerShell

RB

Vista - copying files referenced in an array...help?

Reply
 
02-28-2008   #1
greatbarrier86


 
 

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
02-28-2008   #2
Shay Levi


 
 

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
02-28-2008   #3
Shay Levi


 
 

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
02-28-2008   #4
greatbarrier86


 
 

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
02-29-2008   #5
Shay Levi


 
 

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
Reply

RB


Thread Tools


Similar Threads for: copying files referenced in an array...help?
Thread Forum
Prevent DLL from being referenced .NET General
Copying an array and weird things about updating arrays... PowerShell
Newbie question - Copying files listed in an array PowerShell
Copying files to Program Files directory Vista file management
how to assign values to array and how to create array via variable PowerShell


Vista Forums 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 Ltd
Page generated in 0.06722 seconds with 9 queries