Reference containing folder of nant script? - nant

In NANT,if I write a path, how could I , instead of writing "c:\documents and settings" etc, reference the containing folder of the nant script?
Thanks

You can get the current directory of the nant script by calling the project::get-base-directory() function.
project::get-base-directory
You can also get the current directory by calling the directory::get-current-directory function() function.
directory::get-current-directory

Related

Calling script from resource folder in Jenkins shared folder

Have PowerShell script in resource folder and want to use this script in shared library .groovy script which is under vars folder. Is it there a way to do so??
To run a PS script from the resources dir of your shared library, assuming psScript1.ps1 is in your-shared-library/resources/:
powershell "${libraryResource 'psScript1.ps1'}"
This works great, however, it doesn't let you pass in parameters. I can't seem to find a one-line way to do it.
Building on #christopher's answer, here's a two-line solution:
writeFile file: 'tempFile.ps1', text: "${libraryResource 'psScript1.ps1'}"
powershell './tempFile.ps1 -yourParam $yourParam'
In my testing, I found the ./ to start the temp file path to be required.
You can use libraryResource(file-in-resources) (docs) to load a file from the library resources as a text. That you can write to your workspace with writeFile (docs) and execute.
As the library is checked out somewhere next to your workspace you can maybe execute it directly.

Display a nicely formatted path in PowerShell have code how to format for profile

I found a snippet of code that if I paste in PowerShell It displays all of my windows path variables on one line. What would the syntax be for adding this code to my profile?
Push-Location env:
(ls path).value.split(";")
Pop-Location
Put this function in your PowerShell profile:
function Get-Path {
$env:Path.Split(";")
}
After this function is defined, you can type Get-Path to see the list of directories in your Path.
If you don't already have a profile script, run the command help about_Profiles for more information.
Not sure why you'd prefer to see PATH variable on one line, but here's the code to do it.
C:>(ls Env:\Path).value
I prefer separate lines:
C:>(ls Env:\Path).value.split(';')
As far as your PowerShell Profile goes, open PowerShell and run:
C:>$profile
It will tell you the path to your profile (make the file and directory if it doesn't exist).
Then, copy + paste the code above into it.
It will run whenever you open powershell.

Creating files at PSModulePath in batch

I am currently trying to write a batch program that installs a module named SetConsolePath.psm1 at the correct location. I am a beginner with Batch and I have absolutely no powershell experience.
Through the internet, I have learned how to display PSModulePath with powershell -command "echo $env:PSModulePath.
How can I, via .bat file, move SetConsolePath.psm1 from the desktop to the location displayed by powershell -command "echo $env:PSModulePath?
Thank you in advance, and I apologize for my lack of experience.
Before I answer, I must out that you do not want to copy PowerShell module files directly to the path pointed by PsModulePath. You really want to create a folder inside PSModulePath and copy the files there instead.
The prefix env in a Powershell variable indicates an environment variable. $env:PSModulePath is actually referring to the PSMODULEPATH environment variable. On the command line, and in batch files, environment variables can be displayed by placing the name between percent symbols. (In fact, you could have displayed this value by typing echo %PSMODULEPATH% instead.)
To reference the desktop folder, have a look at this answer, which shows you how to use another environment variable, USERPROFILE.
Therefore, to copy the file from the desktop directory to the path specified in PSModulePath, you would do this:
COPY "%USERPROFILE%\Desktop\SetConsolePath.psm1" "%PSMODULEPATH%"
And, as I warned earlier, you really should copy the file to a folder underneath PsModulePath. So what you really want is:
IF NOT EXIST "%PSMODULEPATH%\MyNewFolder" MKDIR "%PSMODULEPATH%\MyNewFolder"
COPY "%USERPROFILE%\Desktop\SetConsolePath.psm1" "%PSMODULEPATH%\MyNewFolder"

Matlab function call directory

So i had this issue that occurred when I ran a Matlab script. Here is an a simple example that illustrates it:
So its important to outline the file structure:
MainFolder
script.m
SubFolder
a1.csv
a2.csv
a3.csv
now say i have a script like this:
-> script.m
dir
it would simply print out the files in the folder.
Now the wierd thing, if i run the script in the Subfolder like this:
>>script
it will do this:
>> a1.csv a2.csv a3.csv
but if i do this in the folder:
>>run('C:\Users\....\MainFolder\script.m')
it will only print out
>> script.m
So obviously it is acting as if i ran it form MainFolder rather than SubFolder.
What is the point of this functionality?
The dir command shows the directory contents of Matlab's current directory, not that of where the script is located. So the script showed you the directory contents of wherever you happened to be in the Matlab command prompt when you called that script.
To get what you want, use this in the script:
dir(fileparts(mfilename('fullpath')))
Use pwd to see current dir
Use cd to change directory
Use path to see if your project folders are included in the path
Use which to see you are calling the right *.m file (in case there is multiple .m files with same name on the path)

finding a files path in the command line

I am doing a batch scripting assignment where I have to call one script from inside another. I need the script to run the second script no matter where my lecturer saves these scripts. How would I do this. Is there some way to find the path of script inside the script and use that to execute the file. Any help would be great. I think I need to use %'s but i'm not sure.
The name of the script is Hello World.bat.
How would I copy Hello World.bat to the C:\ if I don't know which directory the lecturer has placed it in. what command/s would I use so that the copy would work regardless of the scripts location.
I don't see the "DOS" tag, but I'll assume that it is for now. If you want the entire path, you can get it by doing this:
echo %cd%
If you want just the last folder, this works (inside a .bat file):
for %%* in (.) do #echo %%~n*
Note that from the command line, the above command will work with single %'s:
for %* in (.) do #echo %~n*
If the script you are executing is calling other scripts in the SAME folder location, you can prefix the path statement with "%~dp0" or "%~dps0" but do not put a backslash between that and the name of the script you are calling. In other words, if script1.bat is calling script2.bat in the same folder, the statement in script1.bat would refer to "%~dp0script2.bat"
sorry about batch files, am not familiar, but in nix shell, there is the locate command which can return the path of the file , if you know the filename exactly and the name is unique.
like
name=$(locate filname)