batch

CMD: Delete files/subfolders in a specific directory

Hello, Can someone help me with something I want to achieve in CMD? Say, there is a variable called %pathtofolder%, and, as it makes clear; it is a full path to a folder. Now, what i want to do is, to delete every single file and subfolder in this directory. But not the directory itself. But, there might be an error like 'this file/f...

Skip when error occurs

Hello, i have the following code in batch (cmd): for /f "delims=" %%f in ('dir /b /s Example') do ( command if %errorlevel%==1 ( command SKIP ) command ) EDIT: To make things more clear: for /f... searches for a directory called 'Example' and loops to search for more directories than one. the first command is a delete command, it dele...

Capture dump with adplus.vbs - wait for debugger to finish ?

I have a web application, that sometimes hangs. I want to investigate the reason, and I need to get a memory dump of the process, when it hangs. So my idea is to monitor the website, when I am detecting the hang, I want to start a .bat script which captures the memory dump, then runs IISRESET in order to restart so that the site will st...

Backup DNS Server/s

Hi guys, I have a problem with this script here for /f "tokens=3" %%a in ('netsh interface ip show config ^| find /i "DHCP Enabled"') do set DHCP=%%a If /i "%dhcp%" == "Yes" ( REM do command here ) Else ( REM script to backup DNS servers to environment variables ) I've tried numerous ways using the first for /f example to tr...

How can I make a batch file calling JBOSS to run like a service?

Just curious if theres a way to do this... Basically I'll be calling Jboss from a batch file, and I want to have it run in a seperate thread or service Any idea how to do this? ...

[Batch] write results into a text file

I created a batch that will use windows FINDSTR to search for my selective input. I am trying to log my results of my search term in a text file called results.txt So I do have something like this so results are kept not overwritten: >>Results.txt I've created the txt file so it'll write to it, this is what I tried and won't work: ...

grabbing a subtring in a batch file

I am trying to automate DNS zone creation by using a batch file fired through one of Plesk's events. Using the dnscmd command, the batch checks to see if the zone exists. If the zone does not exist, the script adds it according to specs. If it does exist, and it is a secondary zone, the script deletes and recreates it according to s...

How can I kill child process using taskkill in a batch script?

I'm capturing the PID in a variable which I kill later IF NOT "%SERVICE_PID%" == 0 taskkill /pid %SERVICE_PID% /t /f though everytime I do this in a batch file it makes my computer restart because it kills some system process the service pid should be a user defined service launched from cmd I dont understand why it keeps making ...

"pause" being ignored

I read that I must be able to run all unit tests in my site with a single command, so I created a bat file to do it. Even with pause before the end, after the phpunit command, the result of the unit tests flashes in the screen. @echo off cd c:\ cd xampp cd htdocs cd light cd myworks echo on set /p site=The site: set /p version=The vers...

Batch script to take backup of all *.c and *.h files.

I am new to MS batch programing. I want to copy files with matching regex to destination with same directory structure. If I use dir /b /s, I get full path of source then how can I get the relative path from source path? I want DOS based batch script equivalent of something like this in bash script, file_list=`find ./abc/test -nam...

cmd: variable of open with

Hello, When, for example, i want a batch file to 'open' a file. when i for example drag and drop the file into the batch file, it should do some stuff with that file. Now, i need to know the variable. I know there is a variable for this kind of stuff; i just forgot it. Can someone give me the variable please? Thanks. ...

cmd: unexpected error with @pause and path>txt

Hello, I am coding a batch file. Here is a sample: if exist rootsys.txt del rootsys.txt if %lang%==1 ( if %bit%==32 echo C:\Program Files\path\to\the dir>rootsys.txt if %bit%==64 echo C:\Program Files(x86)\path\to\the dir>rootsys.txt goto :waset ) This goes on for six times (so if %lang%==2 etc... to if %lang%==6.) So, what it does,...

batch/CMD move does not work with folders

Hi everyone. I have a simple .bat (move.bat) file in the SendTo folder which moves files and directories from any location to a specified folder by using the context menu. This worked on XP. In Windows 7 however i get an access denied error. It doesn't even work with cmd opened as admin (runas). content of move.bat: move %1 c:\specified...

"Lights Out" Automated Scheduled Batch Creation of Excel Workbook?

Anybody have a good approach to automate the batch creation of custom-formatted Excel workbooks at a regularly scheduled time or after an event occurs (e.g., file created, table loaded)? To make things even more interesting, let's further assume that the source data is in a relational database or Unix file, and the results need to be e...

CMD: Fails with %1

Hello, Recently i posted a question about what the variable is of a file which you open with a batch file, which is %1. I used this, to let my batch file copy %1 to a specific location. After doing this, debugging and a lot of time, and it actually worked, after debugging it more, adding some features, and some more debugging, it stopp...

CMD: Check for quotes

Hello, Let's say, the user drag and drops an file into my batch file, which causes that the batch file copies the file to a certain directory. the problem is the following command: copy "%1" "C:\path\to\it" The problem here is the quotes around%1. When you drag and drop something in a batch file, normally, it wouldn't put quotes, so ...

Using the PHP -W flag in a batch file

I'm trying to remove all white space and code comments from my .php files by using the -W flag available from the PHP CLI. I'm using a batch file to recursively loop through each php file in my project. The batch command looks like: FOR /F "tokens=*" %%G IN ('DIR /B /A-D /S *.php') DO "%php-exe-path%/php.exe" -w %%G > %%G This just ...

How to check whether a file/dir is writable in batch scripts

In bash, I would use [ -w ... ] What's the equivalent for Windows batch files? ...

What's the environment variable for the path to the desktop?

I'm writing a Windows batch file and want to copy something to the desktop. I think I can use this: %UserProfile%\Desktop\ However, I'm thinking, that's probably only going to work on an English OS. Is there a way I can do this in a batch file that will work on any internationalized version? UPDATE I tried the following batch f...

Long commands split over multiple lines in Windows with quotes

Using the caret to split lines, dir ^ *.bat ^ /w works as expected, but dir ^ "*.bat" ^ won't let me enter the "/w". I guess the caret does not work after a double quote. Is this a bug? Or if this is a feature, what is it's use and how can I get around it? ...