![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Copy-item issue using variable When I try to use a variable in the path name of what I want to copy, it breaks. Here is what I have: $arr = "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" $arr[(Get-Date).month-1] c: del log.txt "Date generated:" | out-file -Append log.txt date | out-file -Append log.txt " " | out-file -Append log.txt "Directory for this month:" | out-file -Append log.txt ($arr[(Get-Date).month-1]+(Get-Date).year) | out-file -Append log.txt " " | out-file -Append log.txt W: mkdir ($arr[(Get-Date).month-1]+(Get-Date).year) F: cd CDS mkdir ($arr[(Get-Date).month-1]+(Get-Date).year) Copy-Item X:\($arr[(Get-Date).month-1]+(Get-Date).year)\*.* F:\CDS\($arr[(Get-Date).month-1]+(Get-Date).year)\*.* | out-file -Append cdslog.txt Everything works fine except for the last Copy-item command. How do I use my variable in the path I want to copy? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Copy-item issue using variable Tip: 0> $arr = 1..3 0> $path = "xxx\$($arr[0])\yyy\$($arr[1] + $arr[2])\zzz" 0> $path xxx\1\yyy\5\zzz In other words, thy to use $(...) Does it help? -- Thanks, Roman |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Copy-item issue using variable Thanks. I was checking the manual and had it down to either quotes or parentheses. ![]() "Roman Kuzmin" wrote: > Tip: > > 0> $arr = 1..3 > 0> $path = "xxx\$($arr[0])\yyy\$($arr[1] + $arr[2])\Zzz" > 0> $path > xxx\1\yyy\5\Zzz > > In other words, thy to use $(...) > Does it help? > > -- > Thanks, > Roman > > > |
My System Specs![]() |
| | #4 (permalink) |
| | RE: Copy-item issue using variable I got it in better form by doing what you said, but i am still having trouble specifically with the copy command. "Archive directory for this month:" | out-file -Append cdslog.txt "$frompath" | out-file -Append cdslog.txt " " | out-file -Append cdslog.txt "Destination folder:" | out-file -Append cdslog.txt "$topath" | out-file -Append cdslog.txt F: cd CDS mkdir ($arr[(Get-Date).month-1]+(Get-Date).year) X: cd $frompath ##Copy-Item "$frompath" "$topath" ##Copy-Item "$frompath" "$topath" | out-file -Append cdslog.txt Help! So close... "JMinahan" wrote: > When I try to use a variable in the path name of what I want to copy, it > breaks. Here is what I have: > > > $arr = "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" > $arr[(Get-Date).month-1] > > c: > del log.txt > > "Date generated:" | out-file -Append log.txt > date | out-file -Append log.txt > " " | out-file -Append log.txt > > "Directory for this month:" | out-file -Append log.txt > ($arr[(Get-Date).month-1]+(Get-Date).year) | out-file -Append log.txt > " " | out-file -Append log.txt > > W: > mkdir ($arr[(Get-Date).month-1]+(Get-Date).year) > F: > cd CDS > mkdir ($arr[(Get-Date).month-1]+(Get-Date).year) > > Copy-Item X:\($arr[(Get-Date).month-1]+(Get-Date).year)\*.* > F:\CDS\($arr[(Get-Date).month-1]+(Get-Date).year)\*.* | out-file -Append > cdslog.txt > > > Everything works fine except for the last Copy-item command. How do I use my > variable in the path I want to copy? |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Copy-Item : Container cannot be copied onto existing leaf item. | PowerShell | |||
| Can the copy-item cmdlet be used to copy public folders to C: ? | PowerShell | |||
| copy-item changing files attributes on network copy failures | PowerShell | |||
| Getting Copy-Item to display messages (like the old COPY command in CMD.EXE) ?? | PowerShell | |||
| Remove-item on a variable name using a regex | PowerShell | |||