![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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
Posts: n/a
| Copying files from the same location as the script Hi, I've got a script that i'm executing from C:\MININT. Part of that script copies files using the copy-item command. To execute it, i run powershell C:\Minint\Script.ps1. However, it errors out when it tries to reference any certain file because it is still trying to look in the path i executed it from instead of the path in which the script is located. Is there something i forgot to type in to tell it to look in the script path? |
| | #2 (permalink) | ||||||||||||
| Guest
Posts: n/a
| Re: Copying files from the same location as the script You can cd into that dir and perform the copy: # Adds the current location to the top of a list of locations ("stack"), *remember* the current location pushd $pwd cd C:\MININT copy-item file.ext ... # changes the current location to the location most recently pushed onto the stack (pushd) popd Or append each file name to the script's current directory : $workingDirectory = Split-Path -Parent $MyInvocation.MyCommand.Path copy-file $workingDirectory\file.ext ... ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
| ||||||||||||
| | #3 (permalink) | ||||||||||||||||||||||||
| Guest
Posts: n/a
| Re: Copying files from the same location as the script Thanks Shay. The problem with those is if those files are moved to C:\Temp for instance, the ps file will have to be adjusted to accomodate that. Is there a way to just have it see those files as the same place as the script? "Shay Levi" wrote:
| ||||||||||||||||||||||||
| | #4 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest
Posts: n/a
| Re: Copying files from the same location as the script You can cd into temp and perform the copy. ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
| ||||||||||||||||||||||||||||||||||||
| | #5 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest
Posts: n/a
| Re: Copying files from the same location as the script You can use this to get the path of the script: $MyLocation = (Split-Path $myinvocation.MyCommand.path -Parent) greatbarrier86 wrote:
| ||||||||||||||||||||||||||||||||||||
| | #6 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest
Posts: n/a
| Re: Copying files from the same location as the script There is no need to include -Parent, it's the default split location parameter ![]() ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com
| ||||||||||||||||||||||||||||||||||||
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| script location? | Justin Rich | PowerShell | 5 | 05-15-2008 11:55 AM |
| Windows Script Host has no script engine for ".js" files | Stephan G. | Vista General | 9 | 04-24-2008 03:04 PM |
| Copying files to Program Files directory | Parrot | Vista file management | 13 | 08-23-2007 01:14 AM |
| how to determine a script location? | Jeff Jarrell | PowerShell | 6 | 06-01-2007 02:56 PM |
| script location and $pwd | Doug | PowerShell | 4 | 12-11-2006 02:47 PM |