Delete many files, need help for creating

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
newbieasking
Posts: 5
Joined: 03 Jan 2018 02:32

Delete many files, need help for creating

#1 Post by newbieasking » 03 Jan 2018 03:46

I wanna delete many files for cleaning the hd.
But win does only offer
del and then I must jump to every directory and I wanna delete some thousands files.
The files are dirt like
*.fmt
*.bak

or 1.gif with one kb
and this came from downloading.

So how can I write a batch file for dos
which is deleting the files I want like
test123.txt
but
name.txt
should not be deleted.

I wrote a batch for my own files and there I delete
every directory once a week file by file
but I know the files and the directories.
The problem is there an many unknown directories
and how can I find them and clean one by one with a batch task?
Thank You.



I m sure

del *.fmt /s
ist not possible, isnt it?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Delete many files, need help for creating

#2 Post by aGerman » 03 Jan 2018 11:06

https://www.dostips.com/DosCommandIndex.php#DEL
del and then I must jump to every directory and I wanna delete some thousands files.
The files are dirt like
*.fmt
*.bak

Code: Select all

del /f /s /q /a *.fmt *.bak
or 1.gif with one kb

Code: Select all

for /f "delims=" %%i in ('dir /a-d /b /s *.gif') do if %%~zi leq 1024 del /f /a "%%~i"
... or use FORFILES
So how can I write a batch file for dos
We are talking about Windows, don't we?
which is deleting the files I want like
test123.txt
but
name.txt
should not be deleted.
Most likely you want to use a pattern like

Code: Select all

del /f /s /q /a "test*.txt"
... not sure though.

Everything untested so far...

Steffen

newbieasking
Posts: 5
Joined: 03 Jan 2018 02:32

Re: Delete many files, need help for creating

#3 Post by newbieasking » 04 Jan 2018 08:01

Thank You for Your friendly help.
*
del /f /s /q /a *.fmt *.bak
*
SO del /s does really work? I ll try.
Thank You.
We use WIN XP but BATCH we call DOS cause its looking like DOS.
*
Do You know an URL, were there is a batch workshop for learning to use batch?

*
delims
Thank You for this task. We ll study it.

***
Is there a opportuny to find and to delete:

Delete all files created in May 2,013.

Delete all files when there a copy exists example a.gif ist in folder FILEs and in folder OLD

Delete all TEXTFILES with a word in the file for example error.

Thank You again.

**
Can del delete a diectory or can DEL delete only files?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Delete many files, need help for creating

#4 Post by Squashman » 04 Jan 2018 08:48

newbieasking wrote:
04 Jan 2018 08:01
del /f /s /q /a *.fmt *.bak

SO del /s does really work? I ll try.
Did you happen to read the help file for the DEL command by typing del /? or help del at the command prompt?
newbieasking wrote:
04 Jan 2018 08:01
Do You know an URL, were there is a batch workshop for learning to use batch?
Well you could start at the main DosTips website.

newbieasking
Posts: 5
Joined: 03 Jan 2018 02:32

Re: Delete many files, need help for creating

#5 Post by newbieasking » 04 Jan 2018 08:56

Another problem, thank You again.
del /f /s /q /a *.fmt
So I think its possible to do something like:


del /f /s /q /a c:\dir1/dir2/dir3/*.fmt

so del should see only the directory

c:\dir1/dir2/dir3
and del is ignoring the rest of the HD.

Is that task ok:
del /f /s /q /a c:\dir1/dir2/dir3/*.fmt




Sorry we are beginners.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Delete many files, need help for creating

#6 Post by Squashman » 04 Jan 2018 09:16

newbieasking wrote:
04 Jan 2018 08:56
Another problem, thank You again.
del /f /s /q /a *.fmt
So I think its possible to do something like:


del /f /s /q /a c:\dir1/dir2/dir3/*.fmt

so del should see only the directory

c:\dir1/dir2/dir3
and del is ignoring the rest of the HD.

Is that task ok:
del /f /s /q /a c:\dir1/dir2/dir3/*.fmt




Sorry we are beginners.
Why ask if it is ok? Test it instead and see what it does. If it doesn't do what you want it to do then ask a question.

newbieasking
Posts: 5
Joined: 03 Jan 2018 02:32

Re: Delete many files, need help for creating

#7 Post by newbieasking » 04 Jan 2018 09:18

I ask
because I dont wanna delete good files.
Delete is delete and we did delete so many good files by bad concentration.
So the task ist fine.
Thank You.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Delete many files, need help for creating

#8 Post by Squashman » 04 Jan 2018 09:37

newbieasking wrote:
04 Jan 2018 09:18
I ask
because I dont wanna delete good files.
What is stopping you from creating a TEST folder to test code on?
Why not create a folder: C:\testing\dir1\dir2\dir3
Copy or create a bunch of random files in it.
And test your command.

newbieasking
Posts: 5
Joined: 03 Jan 2018 02:32

Re: Delete many files, need help for creating

#9 Post by newbieasking » 05 Jan 2018 05:18

Dont worry.
Yesterday we filled a USB Stick with fake files and we did start experiencing.

Delete is dangerous.

So You can see we are beginners so some quetions more:

1
Can we ask
delete all files with fmt in the directory filesjanuary and tell me
how many files did You delete?

2
Tell me also how much free space did You create.

3
Do a list of all deleted files in a textfile result.txt.


4
How can I say

delete is and its gone
and
as other way put the files in the waste paper basket so I can control it before I delete it forever.

5
How can I solve this problem
we have it on our testfiles:

a

There are many files from downloading with the nam a or y or so
and not a.png or a.jpg just a

So we did

del a

and then all other "A" files are deleted also
so how can I tell the system:
delete onyl a but dont delete a.jpg
or what did we do wrong?

Regards and again thank You for the professional help.

Post Reply