Solved Batch Script Intermediate question

August 14, 2012 at 16:00:56
Specs: Windows XP
So my issue is Variable assignment.
My goal is to find for a set of files, report any instance of said file(s) occurrence and then delete them.
If at all possible I'd like help with the variable assignment and not the entire program written.

My solution thus far is this

set fpath=Dir C:\ /p /s | find /i "FileName"

if EXIST %fpath% echo DELETING FILE & DEL %fpath%

This doesn't work. Any pointers would be great

See More: Batch Script Intermediate question

Report •

August 14, 2012 at 16:47:58
✔ Best Answer
Batch does not work like most other languages were you can set a variable directly by setting its value to a command.

Your code after the parsing phase looks like this:

if EXIST Dir C:\ /p /s | find /i "FileName" echo DELETING FILE & DEL %fpath%

That will not work.

@echo off
set fname=filename
for /f "tokens=*" %%i in (
'dir /s /b %fname%'
) do (
echo DELETING FILE & >nul del "%%i"


Report •

August 15, 2012 at 01:06:19
or simply

del /s c:\*.bak

Life is too important to be taken seriously.


Report •

August 16, 2012 at 12:34:40
It is unfortunate that batch scripts are so limited but I must make due with the system I have and the constraints placed upon me as an Admin. Thanks for the help! Kudos.

Report •

Related Solutions

Ask Question