Computing.Net > Forums > Disk Operating System > help!! I need delete a file in sev

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

help!! I need delete a file in sev

Reply to Message Icon

Name: terrydq
Date: August 24, 2002 at 11:15:45 Pacific
Comment:

I need delete a file in several directories at the same time



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: August 24, 2002 at 17:04:51 Pacific
Reply:

Don't you think "in several directories" is too much vague?

Anyway, the following batch file will delete all files named "filename.ext" which are on or under the directory "c:\main" (those values may be changed, read commented lines):

===== BATCH SCRIPT BEGIN =====
@echo off
if "%1"=="GoTo:" GOTO %2
if not "%OS%"=="" goto eof
%COMSPEC% /e:2048 /c %0 GoTo: start
goto eof
:start
set Q=
if not "%windir%"=="" set Q="
set dircmd=

:: To activate the script, remove
:: "echo.{demo}" from next line
prompt echo.{demo}DEL %Q%

:: Set location to look for files (c:\main)
:: and filename (filename.ext) below
:: ******************************
:: IMPORTANT: THE EXTENTION FROM
:: THE FILE MUST **NOT** BE AN
:: AN EXECUTABLE (COM EXE or BAT)
:: ******************************
dir/b/s/a-d c:\main\filename.ext> %TEMP%.\T1.BAT

ctty nul
%COMSPEC% /c %TEMP%.\T1.BAT > %TEMP%.\T2.DAT
ctty con
FIND "\" < %TEMP%.\T2.DAT > %TEMP%.\T1.BAT
call %TEMP%.\T1.BAT
for %%? in (T1.BAT T2.DAT) do del %TEMP%.\%%?
:eof
===== BATCH SCRIPT END =====

Watch out for line wrapping! The script is de-activated. When you run it, it will display a demonstration of the actions it would take if active. If those are the intented actions, activate the script (read commented lines to do so).

That script is for Win9x/DOS only, not NT systems. On those, use this:

for /R %I in (.\filename.ext) do if exist %I del %I

That would be run from the command prompt, under the directory where the files to be deleted are (it will look on subdirectories). If you intend to put that into a batch file, replace %I for %%I

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: help!! I need delete a file in sev

I need to delete a file in DOS www.computing.net/answers/dos/i-need-to-delete-a-file-in-dos/12292.html

how do I delete a file anywhere on the disk? www.computing.net/answers/dos/how-do-i-delete-a-file-anywhere-on-the-disk/2273.html

Making DOS Batch Files In a Batch File www.computing.net/answers/dos/making-dos-batch-files-in-a-batch-file/3094.html