Batch – copy file using relative path
if you start your path with \, it’s an absolute, not a relative path. Try copy “Debug\text.txt” “..\..\new” instead
if you start your path with \, it’s an absolute, not a relative path. Try copy “Debug\text.txt” “..\..\new” instead
In this answer the ERRORLEVEL values returned by all internal cmd.exe commands are described; they are grouped by the way the value is changed and presented as quick reference tables. I reviewed other similar tables in order to assemble this one, but filled the missing values via tests performed in a Windows 8.1 computer. I … Read more
The set statement doesn’t treat spaces the way you expect; your variable is really named Pathname[space] and is equal to [space]C:\Program Files. Remove the spaces from both sides of the = sign, and put the value in double quotes: set Pathname=”C:\Program Files” Also, if your command prompt is not open to C:\, then using cd … Read more
It represents the first command line argument passed to the batch file. If you run your batch file with: myfile.bat firstArg secondArg %1 becomes “firstArg” and %2 becomes “secondArg” The related shift command shifts the position of arguments one to the left. Running shift once in a batch file will make “%1” value to be … Read more
Possibly the npm program is a batch file itself. Then you need to use call, as only then the program control returns to the caller. call npm install -g bower call npm install -g grunt-cli call npm install call gem update –system –verbose call gem install compass –verbose pause
To get help for command prompt commands use their /? option. Exit /? shows: Quits the CMD.EXE program (command interpreter) or the current batch script. EXIT [/B] [exitCode] /B specifies to exit the current batch script instead of CMD.EXE. If executed from outside a batch script, it will quit CMD.EXE exitCode specifies a numeric number. … Read more
Or you can create a “real” newline character. setlocal enableDelayedExpansion set NL=^ rem two empty line required echo first line !NL! second line set multi=Line1!NL!Line2 set multi=!multi!!NL!Line3 echo !Multi! With this variant the newline is a “normal” character in the string, so the variables act normally and you can assign them to another variable, this … Read more
Adapted from this answer to a very similar question: FORFILES /S /D -10 /C “cmd /c IF @isdir == TRUE rd /S /Q @path” You should run this command from within your d:\study folder. It will delete all subfolders which are older than 10 days. The /S /Q after the rd makes it delete folders … Read more
The caret ‘^’ character serves two purposes in Windows batch files: 1. line continuations: ~~~ @echo off dir ^ /ad ^ c:\temp ~~~~ results in dir /ad c:\temp, which lists only the directories in C:\temp. 2. Escaping reserved shell characters & | ( < > ^. Use a preceding caret to escape and print the … Read more