ms-dos

Easy installation method for windows/ Batch Reference needed?

I have a bunch of files that I need to be able to transport and install quickly. My current method for doing so is moving a flash drive with a readme file of where stuff goes whenever I need to move stuff, which is rather inelegant and cumbersome. My idea for a solution would be to write up a quick script to move files around that I cou...

How to Pass Command Line Parameters in batch file

I needed to pass id and password to a cmd (or bat) file at the time of running rather than hardcoding them into the file. Here's how I do it. echo off fake-command /u %1 /p %2 Here's what the command line looks like: test.cmd admin P@55w0rd > test-log.txt The %1 applies to the first parameter the %2 (and here's the tricky part) ap...

DOS filename escaping for use with *nix commands

I want to escape a DOS filename so I can use it with sed. I have a DOS batch file something like this: set FILENAME=%~f1 sed 's/Some Pattern/%FILENAME%/' inputfile (Note: %~f1 - expands %1 to a Fully qualified path name - C:\utils\MyFile.txt) I found that the backslashes in %FILENAME% are just escaping the next letter. How can I do...

Open one of a series of files using a batch file

I have up to 4 files based on this structure (note the prefixes are dates) 0830filename.txt 0907filename.txt 0914filename.txt 0921filename.txt I want to open the the most recent one (0921filename.txt). how can i do this in a batch file? Thanks. ...

Is there a clean way to prevent windows.h from creating a near & far macro?

Deep down in WinDef.h there's this relic from the segmented memory era: #define far #define near This obviously causes problems if you attempt to use near or near as variable names. Any clean workarounds? Other then renaming my variables? ...

Command line .cmd/.bat script, how to get directory of running script

How can you get the directory of the script that was run and use it within the .cmd file? ...

Is it possible to modify a registry entry via a .bat/.cmd script?

Is it possible to modify a registry value (whether string or DWORD) via a .bat/.cmd script? ...

.cmd and .bat file converting return code to an error message

I'm trying to automate a program I made with a test suite via a .cmd file. I can get the program that I ran's return code via %errorlevel%. My program has certain return codes for each type of error. For example: 1 - means failed for such and such a reason 2 - means failed for some other reason ... echo FAILED: Test case failed,...

How can you echo a newline in batch files?

How can you you insert a newline from your batch file output. I want to do something like: > echo hello\nworld Which would output: hello world ...

Test automation using batch files:

I have the following layout for my test suite: TestSuite1.cmd: Run my program Check its return result If the return result is not 0, convert the error to textual output and abort the script. If it succeeds, write out success. In my single .cmd file, I call my program about 10 times with different input. The problem is that the pro...

How can I load the contents of a text file into a batch file variable?

I need to be able to load the entire contents of a text file and load it into a variable for further processing. How can I do that? Here's what I did thanks to Roman Odaisky's answer. SetLocal EnableDelayedExpansion set content= for /F "delims=" %%i in (test.txt) do set content=!content! %%i echo %content% EndLocal ...

batch find file extension

If I am iterating over each file using : @echo off FOR %%f IN (*.*) DO ( echo %%f ) how could I print the extension of each file? I tried assigning %%f to a temporary variable , and then using the code : echo "%t:~-3%" but with no success . ...

How do I test if a file is a directory in a Batch script?

Is there any way to say if a file is a directory? I have the filename in a variable. In Perl I can do this: if(-d $var) { print "it's a directory\n" } ...

Windows batch files: .bat vs .cmd?

As I understand it, .bat is the old 16-bit naming convention, and .cmd is for 32-bit Windows, i.e., starting with NT. But I continue to see .bat files everywhere, and they seem to work exactly the same using either suffix. Assuming that my code will never need to run on anyhting older than NT, does it really matter which way I name my ba...

How to do something to each file in a directory with a batch script

How do you iterate over each file in a directory with a .bat or .cmd file? For simplicity please provide an answer that just echo's the filename or file path. ...

string symbol manipulation in batch files?

Is there a way to take substrings of a string with .bat/.cmd files? For example given the string "hello.txt" is there a way to strip the .txt? EDIT: Also is there a more general way to do this, not under the assumption that it is a file name or file path? ...

Best free resource for learning advanced batch-file usage?

What are the best free resources for learning advanced batch-file usage? ...

Persisting an environment variable through ruby

I am trying to set my dos environment variable in ruby which persists after the script exits. For example if I want a ruby script set_abc_env.rb to set environment variable ABC to blah, I expect to have the following: C:> echo %ABC% C:> set_abc_env.rb C:> echo %ABC% blah How do I do this? ...

How to set a long Java classpath in MSDOS/Windows?

I'm trying to run a particular JUnit test by hand on a Windows XP command line, which has an unusually high number of elements in the class path. I've tried several variations, such as: set CLASS_PATH=C:\path\a\b\c;C:\path\e\f\g;.... set CLASS_PATH=%CLASS_PATH%;C:\path2\a\b\c;C:\path2\e\f\g;.... ... C:\apps\jdk1.6.0_07\bin\java.exe -cl...

DOS batch files: How to read a file?

How you can read a file (text or binary) from a batch file? There is a way to read it in a binary mode or text mode? ...