Windows environment variable issue - windows

I have two environment variables defined as:
test1=C:\something\dir1
test2=C:\something\dir2
And I'm trying to run the following command:
copy dir1\filename.txt dir2\filename.txt
I know that if I write the copy command with the environment variables it will work, like below:
copy %test1%\filename.txt %test2%\filename.txt
But isn't there a better way to do this? If Windows doesn't find the "dir1" directory in its current directory, won't it try to find it with the system variables it has?
EDIT: Im trying to use the copy command without typing the enviroment variable's name in the command.
Something like "copy dir1\filename.txt dir2\filename.txt", where, if Windows cant find the dir1 directory in its current directory, it would automatically search this directory with the enviroment variables. Is this possible?

This will copy the fully qualified path and filename, and cater for spaces etc.
copy "%test1%\filename.txt" "%test2%\"
If it doesn't work for you then edit your question and give more details about the task.

Related

How to check your path in Command Prompt

I'm learning Laravel and found this direction on their documentation:
"Make sure to place the ~/.composer/vendor/bin directory in your PATH so the laravel executable is found when you run the laravel command in your terminal." http://laravel.com/docs/4.2/installation#install-laravel
Question:
How exactly I make sure the folder is on my PATH? What's the command?
If I'm not on the PATH, how to get there? I tried to find /.composer/vendor/bin but got nothing.
I'm using Windows 8 64bit.
1) windows: PATH | grep -oP ".composer.*bin"
If it's in the path You'll get a response if it's not you'll get nothing.
2)
~/ refers to home path on linux doing %HOMEPATH% on windows results in the same thing, which in your case would be %HOMEPATH%/.composer/vendor/bin
Doing /somefolder Will go to the root path in linux and try to find a folder there called somefolder but won't do anything in windows, I'm not sure what the equivalent in windows is, might be referring to root of the drive, I.e. C:\ or D:\ etc.
To add .composer/vendor/bin to your home path you need to go to your environmental variables and add it into the path you can go here and follow the steps in the answer or the question.
The important bit:
Example of windows SETX command:
Print the PATH environment variable:
C:\Users\Charity>echo %PATH% C:\windows\system32;C:\windows and
space;C:\foobar Use setx to set the environment variable:
C:\Users\Charity>setx PATH "%PATH%;C:\zombiepoke" SUCCESS: Specified
value was saved. Close and re-open cmd terminal, then run:
C:\Users\Charity>echo %PATH% C:\windows\system32;C:\windows and
space;C:\foobar;C:\zombiepoke You have to be careful with double
quotes. If you let quotes get into your path variable it might break
something. However they are necessary for specifying addendums to the
original %PATH%.
Make note though that this only sets it for the current user context, to set it for all users you have to to use setx /M.
for those who also needs the answer for this question, I found it here.
Basically, all you need is to write:
cd %APPDATA%\Composer\vendor\bin

Is it possible to update svn using a windows environmental variable folder?

I have tortoiseSVN installed alongside subversion for windows (not using TortoiseSVN command client tools because of restrictive purposes).
I have a batch file that runs an svn update on certain folders which are used as environmental variables in Windows. Is it possible to svn update a folder using just the folder name?
e.g. from this:
cd C:\foo\johnsmith\testing\
svn update
to something like this?
cd testing\
svn update
I should add that environmental variables are new to me...
With regards to Alrocs comment, the path C:\foo\johnsmith\testing\ is in the system environmental variable "Path".
You can't cd to directory, which is part of your $PATH$. But you can use environment variable, which explicitly contain needed path only (after all - variable is just string)
c:\TEMP>echo "%USERPROFILE%"
"C:\Documents and Settings\Badger"
c:\TEMP>cd "%USERPROFILE%"
C:\Documents and Settings\Badger>
Never assume anything about environment variables that you haven't set via your batch file. Just because it's there today/on your computer doesn't necessarily mean it'll be there tomorrow or on another computer.
But you aren't using an environment variable in your script in the first place.
If you need to update a specific path, be explicit and update that path by specifying the whole path. Don't assume that your testing directory will be an immediate child of the directory you're running the batch file in unless you can control everything else - the whole subdirectory structure, where the batch file executes from, and how it executes.

Configuring Cyqwin to make using ./ unnecessary

In order for me to run a .exe or a .sh in Cyqwin, I have to put a ./ at the beginning of my line. Is there a way for me to change this so that isn't necessary? This is causing problems when I try and run a test script and it can't find files that are right in the directory I'm working in.
The reason you must use a './' is to specifically tell the shell what file you are trying to execute. Without the leading './', your $PATH environment variable is searched. You can try adding the directories with scripts and executables you commonly use to your $PATH if you'd like. Alternatively, you can add the current directory (.) to your $PATH, but this is a Very Bad Idea as it can lead to unintentional executions.
From the cygwin environment variables doc:
The PATH environment variable is used by Cygwin applications as a list
of directories to search for executable files to run. This environment
variable is converted from Windows format (e.g.
C:\Windows\system32;C:\Windows) to UNIX format (e.g.,
/cygdrive/c/Windows/system32:/cygdrive/c/Windows) when a Cygwin
process first starts. Set it so that it contains at least the
x:\cygwin\bin directory where "x:\cygwin is the "root" of your cygwin
installation if you wish to use cygwin tools outside of bash.

Where do I put mxmlc so that I could just type 'mxmlc' in the terminal to compile a swf file?

I'm on a Mac and I'm trying to make a Vim plugin for compiling/running actionscript files.
First, I need to run mxmlc on the command line, but to do that I have to keep on typing the path to it. Where do I place it so that I don't have to retype the path?
You need to modify your "$PATH" environment variable, so that the tool is in that directory. However, if you want to make this very easy... you can download my macosx-environment-setup.tar.bz2 program. If you execute the "install.sh" script using "sudo ./install.sh", it will setup your environment in such a way that if you use "/Library/Flex4SDK" as the location for the Flex4SDK, it will automatically find it, define FLEX_HOME to point to that location, and it will also ensure that the binaries from the Flex4SDK are in your PATH.
Side Note: This is up on the web, because I use it in my Development Environment Setup How-To Guides. If you aren't too keen about running "sudo ./install.sh", you need to choose a location (I am going to assume "/Library/Flex4SDK", so that the tools are located in "/Library/Flex4SDK/bin"), and then you would simply need to edit your "~/.profile" file (using "nano ~/.profile"), adding the following to the very end:
export FLEX_HOME=/Library/Flex4SDK
export PATH="$PATH":"$FLEX_HOME/bin"
Note that these changes occur in your shell... they will not affect programs that are launched by double-clicking them in Finder. In order to affect those programs, you will need to place the environment variables in a file named ~/.MacOSX/environment.plist. See Automatically build ~/.MacOSX/environment.plist for a script that will automatically generate such a file using the current environment variables defined in your shell.
There are a few ways to answer this:
In one of your directories searched
by PATH (see the list with echo
$PATH)
Add a new directory to PATH
(e.g. in your ~/.bashrc
export PATH=$PATH:/path/to/bindir)
Add an
alias to your program (e.g. in your
~/.bashrc alias
mxmic=/path/to/mxmic)
(I'm assuming you're using bash shell, which is usually the case you can check with echo $SHELL)

Relative file paths

I am trying to read in from a few files using something like this
IO.foreach("TeamFields.txt") { |line| fieldNames.push(line.chomp) }
It works fine when running the from the command line, but when I package to an .exe with shoes and run it can't find the file. Is there a way to specify a path relative the the .exe or do I have to provide the full filepath (e.g. "c:\files\TeamFields.txt")? Thanks for the help.
This is because your executable is not run with the correct current directory.
Either fix the current directory (for example in the shortcut) or modify your Ruby program to automatically set the working directory to the program directory with:
Dir.chdir(File.dirname($PROGRAM_NAME))
You need to set "Current Application Directory" correctly before going relative.
The user can execute your app with different start up dir, or system can call your app with different dir.
If files in question are in the folder of your app, the only thing you need to do is to get that folder, and set it to be current.
I don't program in ruby, but I do with windows, and odds are the relative path will be based on the location of the .exe file.
So, yes, you're probably better off passing a full path for the file name.
The constant __FILE__ will contain the full path to the currently executing file. You can then use methods of the File class to strip off the filename, append the relative path for whatever other file in your package it is you want and resolve the result.

Resources