Solved Advanced(?) batch script problem (2008 R2)

May 20, 2011 at 12:31:43
Specs: Windows 2008 R2
Hi all,

I'm trying to solve a fairly simple task using a batch script, and in a nutshell it's driving me...well, nuts!

I have a backup directory (e.g. C:\tmp1\) that contains what looks like the root of drive C, so C:\tmp1\Windows\ for example. I want to copy all of the contents of tmp1 to another location, but here is the catch: I have a text file that contains files that need to be deleted before the copy takes place. So for example:

# This is a comment

The line beginning with ! would need to be translated into C:\tmp1\Windows\System32\foo.dll and then deleted. There are many exclude lines and comments in the text file. Another concern is that I would need to run takeown / icacls in order to guarantee deletion.

I could knock this out in Bash script no problem, but Batch

Many thanks!!

See More: Advanced(?) batch script problem (2008 R2)

Report •

May 21, 2011 at 10:52:54
✔ Best Answer
:: ==========================================
:: ian1981.bat Sun 22-05-2011 0:33:00.48
@echo off & setLocal enableDELAYedeXpansioN

for /f "tokens=* delims= " %%a in ('findstr /v /b /c:# filelist') do (
echo del C:\tmp1%%a

Life is too important to be taken seriously.


Report •

May 22, 2011 at 08:17:47
Thanks M2! That works great from within a script.

I'm curious though, how does it know to chop off the "!C:" part at the beginning of the string? When I run a similar "for" command simply on the command line, it doesn't chop it off.

Without any explicit cutting/chopping, I would expect %%a to be:


Report •

May 22, 2011 at 23:44:53
! has special meaning within a bat with:

setLocal enableDELAYedeXpansioN

Maybe IVO can explain.

Life is too important to be taken seriously.


Report •

Related Solutions

May 28, 2011 at 01:13:05
M2, Someone neeeds your help..

this is written by you and i think u can help him agan

Subhash Chandra.

Report •

Ask Question