Avatar of RandallVillalobos
RandallVillalobosFlag for Costa Rica asked on

Delete multiple text files via dos command line

Experts,

I need to remove multiple text files via the command line.
In example:
C:\1.txt
C:\2.txt
C:\3.txt
C:\4.txt
C:\5.txt

------------

I tried the following batch file with no success, deletes the first line and then the batch files just "HANGS".

@echo off
del /q /s \\computername1\c$\1.txt
del /q /s \\computername1\c$\2.txt
etc etc etc
Microsoft DOSShell ScriptingMicrosoft Legacy OS

Avatar of undefined
Last Comment
Lee W, MVP

8/22/2022 - Mon
Lee W, MVP

why not:

del /q /s \\computername1\c$\*.txt

Put the computer names in a text file.  Then use this:

for /f "tokens=*" %%a in (textfile.txt) do del /q /s \\%%a\c$\*.txt
telczj9

Randal,

careful that:

del /q /s \\computername1\c$\1.txt

does not hang.  The "/s" flag is looking for instances of "1.txt" in all subdirectories and if it finds them it will delete them from all subdirectories.

del /q \\computername1\c$\1.txt

would only delete "1.txt" in the c:\ drive of computername1.

Cheers!
SOLUTION
telczj9

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Darr247

Usually the root of a drive is not shared, ergo you would not have permission to delete C:\*.txt

What version[s] of windows are you using?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
telczj9

try "net share" from windows 7 down see what you get :)
Darr247

Go to another machine and try deleting a file from that 'default share'.
telczj9

would mind qualifying "Usually the root of a drive is not shared"...

C:\>type \\<host_name>\c$\test.txt
7:49 PM 9/22/2011
C:\>del /q \\<host_name>\c$\test.txt

C:\>type \\<host_name>\c$\test.txt
The system cannot find the file specified.

C:\>

;)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
RandallVillalobos

Awesome knowledge! thanks for sharing.
Let me test it out!
Don Thomson

Darr247 is correct

Usually the root of the Sys drive is not shared - in the normal sense

If you are running XP PRo, Vista PRo or Win7 Pro and are not using simple sharing then there is only an Administrative share on the actual root of the hard drives.

It is just a bad idea from a security point of view to do a visible share on the root - The c$ is not visible when looking at the network (For that matter anything that has a $  after the share name is a hidden share. Most IT departments will only put normal visible shares  on folders that are available to all users. Things like accounting folders should be shared as accounting$ and then if a drive needs to be mapped for someone that needs access to that folder - is is either done manually or via the login profile on a DC

From a security point of view - no one but the administrator should have access to the Root of any users PC - In the case that  Randall is asking about - the files that need to be deleted should be put in a folder off the root - not in the root itself. There are many reasons for this - especially on some of the older OS. I remember working on systems that were extremely slow that we found thousands of files in the root directory - What we found was any more than 256 ITEMS (Files or Folders) in the Root directory caused the PC to grind to a halt.  Any other folder was good for more items but not the root - keep it clean
Lee W, MVP

Your right, I didn't check the switches carefully on the del command.  The problem is, the question is too vague from my perspective and I should have requested clarification.

What can really help a solution is understanding WHY the user needs to do these things and what application is generating the files.  Why would you be deleting every file named 1.txt, 2.txt, etc on a drive?  I'm pretty sure those aren't actual file names, but if we knew more, a better solution might present itself.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER
RandallVillalobos

Hi Everybody thanks for all the assistance.  This is the entire story:
The IT department received an incorrect package file for deployment. This file creates a folder "XYZ" and outside on the "ABC" folder it  includes .exe, text files and .doc  files.

The path is
C:\Program Files\ABC\XYZ
Inside the ABC folder, we find many .exe and .txt files that we don't need.

So I want to delete the entire"XYZ" folder, and many of the .exe, .txt and .doc folder on the "ABC" directory.

In example
Path : C:\Program Files\ABC
delete "test.txt"
delete "file.doc"
delete "program.exe"

Path : C:\Program Files\ABC\XYZ  (delete the entire "XYZ" folder and everything inside of it.

I hope this clarifies what I'm trying to accomplish on a whole bunch of computers.

thanks!
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
RandallVillalobos

Thanks, I believe that scripting is something I will enjoy.
If you have any recommended websites links that provide an explanation to all this parameters it will be great!
Lee W, MVP

Scripting (in batch) is just knowing what the commands do and what information is likely to be returned and a series of delete commands IS a script... but where things are repetitive, loops should be looked at.

As for sites, for reference, i prefer ss64.com - reference the cmd section.

As basic tutorials, I recommend www.robvanderwoude.com
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.