![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| | |||||||
| | Vista - copying files referenced in an array...help? |
| |
| 02-28-2008 | #1 |
| | 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 Specs |
| 02-28-2008 | #2 |
| | 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 Specs |
| 02-28-2008 | #3 |
| | 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 Specs |
| 02-28-2008 | #4 |
| | 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 Specs |
| 02-29-2008 | #5 |
| | 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 Specs |
![]() |
| 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 | |||