Tagged Questions
34
votes
7answers
9k views
How does the Windows Command Interpreter (CMD.EXE) parse scripts?
I ran into ss64.com which provides good help regarding how to write batch scripts that the Windows Command Interpreter will run.
However, I have been unable to find a good explanation of the grammar ...
188
votes
15answers
297k views
Batch file to delete files older than N days
I am looking for a way to delete all files older than 7 days in an MS-DOS batch file. I've searched around the web, and found some examples with hundreds of lines of code, and others that required ...
101
votes
17answers
176k views
How can you find and replace text in a file using the Windows command-line environment?
I am writing a batch file script using Windows command-line environment and want to change each occurrence of some text in a file (ex. "FOO") with another (ex. "BAR"). What is the simplest way to do ...
121
votes
17answers
75k views
How to measure execution time of command in windows command line?
Can this be done with standard means?
125
votes
18answers
245k views
How to get current datetime on Windows command line, in a suitable format for using in a filename?
What's a Windows command line statement(s) I can use to get the current datetime in a format that I can put into a filename?
I want to have a .bat file that zips up a directory into an archive with ...
77
votes
10answers
158k views
How to check if a process is running via a batch script
How can I check if an application is running from a batch (well cmd) file?
I need to not launch another instance if a program is already running. (I can't change the app to make it single instance ...
176
votes
11answers
94k views
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 ...
17
votes
2answers
34k views
Setting a system environment variable from a Windows batch file?
Is it possible to set a environment variable at the system level from a command prompt in Windows 7 (or even XP for that matter). I am running from an elevated command prompt.
set name=value seems to ...
67
votes
6answers
47k views
What does %~d0 mean in a Windows batch file?
I'm looking at a batch file which defines the following variables:
set _SCRIPT_DRIVE=%~d0 set
set _SCRIPT_PATH=%~p0
What do %~d0 or %~p0 actually mean? Is there a set of well-known values for ...
13
votes
5answers
17k views
Parallel execution of shell processes
Is there a tool available to execute several process in parallel in a Windows batch file? I have found some interesting tools for Linux (parallel and PPSS), however, I would need a tool for Windows ...
2
votes
2answers
3k views
'Pretty print' windows %PATH% variable - how to split on ';' in CMD shell
I want to run a simple one-liner in the Windows CMD prompt to print my %PATH% variable, one entry per line.
I tried this: for /f "delims=;" %a in ("%path%") do echo %a but this only prints the first ...
50
votes
5answers
53k views
Windows XP or Vista: How can I run a batch file in the background (no windows displayed)?
I know I have already answered a similar question (Running Batch File in background when windows boots up), but this time I need to launch a batch:
From another batch
Without any DOS windows ...
43
votes
9answers
65k views
How do you loop through each line in a text file using a windows batch file?
I would like to know how to loop through each line in a text file using a Windows batch file and process each line of text in succession.
30
votes
7answers
37k views
Can Windows' built-in ZIP compression be scripted?
Is the ZIP compression that is built into Windows XP/Vista/2003/2008 able to be scripted at all? What executable would I have to call from a BAT/CMD file? or is it possible to do it with VBScript?
I ...
64
votes
20answers
183k views
How to sleep for 5 seconds in Windows's Command Prompt? (or DOS)
Windows's Snipping tool can capture the screen, but sometimes I want to capture the screen after 5 seconds, such as taking an image being displayed by the webcam. (run the script and smile at the ...