DEL command help

  • Thread starter Thread starter Ben Rum
  • Start date Start date
B

Ben Rum

Is it possible to issue a DEL command which deletes files based on an
alpabetical less than or greater than?

Basically as follows: (delete all files which are alphabetically less than
"G" for example)
C:> DEL < G*.*
or
C:> DEL [a-f]*.*

Anythig like that exist?

Thanks,
 
Is it possible to issue a DEL command which deletes files based on an
alpabetical less than or greater than?

Basically as follows: (delete all files which are alphabetically less than
"G" for example)
C:> DEL < G*.*
or
C:> DEL [a-f]*.*

Anythig like that exist?

Thanks,
No, but:

setlocal ENABLEDELAYEDEXPANSOPN
cd /d c:\folder
for /f "Tokens=*" %%a in ('dir *.* /b /a') do (
set fn=%%a
if "!fn:~0,1!" LSS "G" del /q "%%a"
)
endlocal
 
Hey Jerold!

Hope you're well ... I looked at that approach too ... a nice job btw.
I eventually decided that I'm too anal and couldn't tolerate the fact
that its LESS-THAN logic incorporated a variety of other (mostly
grammatical) characters which may have a completely undesirable result
.... especially in the case of a delete operation.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l

Jerold said:
Is it possible to issue a DEL command which deletes files based on an
alpabetical less than or greater than?

Basically as follows: (delete all files which are alphabetically
less than "G" for example)
C:> DEL < G*.*
or
C:> DEL [a-f]*.*

Anythig like that exist?

Thanks,
No, but:

setlocal ENABLEDELAYEDEXPANSOPN
cd /d c:\folder
for /f "Tokens=*" %%a in ('dir *.* /b /a') do (
set fn=%%a
if "!fn:~0,1!" LSS "G" del /q "%%a"
)
endlocal
 
Hi Dean, I couldn't get the command working. See the command prompt output
below

Also, I actualy simplified the scenario in my original post, I actually want
to delete files which are named with a date prefix: i.e. 20050105_EXPORT.zip
and so on.. I want to be able to delete files which are dated older than 14
days. So the first letter isn't quite enough for what I am looking for.

I can easily produce the date part of the command via the SQL tool (i.e "del
20050105_EXPORT.zip") so if today is 20050822, I can easily produce "del
20050807*.zip" but it's the less than part I can't do...

[from command prompt window]
E:\MAPPED\TESTING>DIR
Volume in drive E is DATA
Volume Serial Number is F034-FCD8

Directory of E:\MAPPED\TESTING

22/08/2005 14:44 <DIR> .
22/08/2005 14:44 <DIR> ..
22/08/2005 14:33 0 AFILE.txt
22/08/2005 14:34 2,089 alphacmd.BAT
22/08/2005 14:33 0 BFILE.txt
22/08/2005 14:33 0 GFILE.txt
22/08/2005 14:33 0 YFILE.txt
22/08/2005 14:34 0 ZFILE.txt
6 File(s) 2,089 bytes
2 Dir(s) 21,488,177,152 bytes free

E:\MAPPED\TESTING>ALPHACMD G

Working ...

del a /-p
del b /-p
del c /-p
del d /-p
del e /-p
del f /-p
del G /-p

E:\MAPPED\TESTING>DIR
Volume in drive E is DATA
Volume Serial Number is F034-FCD8

Directory of E:\MAPPED\TESTING

22/08/2005 14:44 <DIR> .
22/08/2005 14:44 <DIR> ..
22/08/2005 14:33 0 AFILE.txt
22/08/2005 14:34 2,089 alphacmd.BAT
22/08/2005 14:33 0 BFILE.txt
22/08/2005 14:33 0 GFILE.txt
22/08/2005 14:33 0 YFILE.txt
22/08/2005 14:34 0 ZFILE.txt
6 File(s) 2,089 bytes
2 Dir(s) 21,488,177,152 bytes free

E:\MAPPED\TESTING>





Dean Wells said:
I can only assume by alphabetically less than 'G' that you're referring
to the first character of the filename? If so, no, not natively ...
though it can be scripted ... the enclosed file achieves precisely that
(it is enclosed as, when pasted and posted, the script becomes too
fragmented and awkward to reconstruct). The file has been renamed to a
text file and needs its extension changed to .BAT or .CMD. Should the
enclosure be inaccessible to you, please post back.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l

Ben said:
Is it possible to issue a DEL command which deletes files based on an
alpabetical less than or greater than?

Basically as follows: (delete all files which are alphabetically less
than "G" for example)
C:> DEL < G*.*
or
C:> DEL [a-f]*.*

Anythig like that exist?

Thanks,
 
As a precaution, you'll notice that the COMMAND variable currently
contains 'echo del' ... this is to prevent you from inadvertently
testing it and deleting a large number of files. Once you're
comfortable that it functions as you'd expect, edit the file and the
line -

set COMMAND=echo del

.... with ...

set COMMAND=del

Let me know if it works out for you.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l

Ben said:
Hi Dean, I couldn't get the command working. See the command prompt
output below

Also, I actualy simplified the scenario in my original post, I
actually want to delete files which are named with a date prefix:
i.e. 20050105_EXPORT.zip and so on.. I want to be able to delete
files which are dated older than 14 days. So the first letter isn't
quite enough for what I am looking for.

I can easily produce the date part of the command via the SQL tool
(i.e "del 20050105_EXPORT.zip") so if today is 20050822, I can easily
produce "del 20050807*.zip" but it's the less than part I can't do...

[from command prompt window]
E:\MAPPED\TESTING>DIR
Volume in drive E is DATA
Volume Serial Number is F034-FCD8

Directory of E:\MAPPED\TESTING

22/08/2005 14:44 <DIR> .
22/08/2005 14:44 <DIR> ..
22/08/2005 14:33 0 AFILE.txt
22/08/2005 14:34 2,089 alphacmd.BAT
22/08/2005 14:33 0 BFILE.txt
22/08/2005 14:33 0 GFILE.txt
22/08/2005 14:33 0 YFILE.txt
22/08/2005 14:34 0 ZFILE.txt
6 File(s) 2,089 bytes
2 Dir(s) 21,488,177,152 bytes free

E:\MAPPED\TESTING>ALPHACMD G

Working ...

del a /-p
del b /-p
del c /-p
del d /-p
del e /-p
del f /-p
del G /-p

E:\MAPPED\TESTING>DIR
Volume in drive E is DATA
Volume Serial Number is F034-FCD8

Directory of E:\MAPPED\TESTING

22/08/2005 14:44 <DIR> .
22/08/2005 14:44 <DIR> ..
22/08/2005 14:33 0 AFILE.txt
22/08/2005 14:34 2,089 alphacmd.BAT
22/08/2005 14:33 0 BFILE.txt
22/08/2005 14:33 0 GFILE.txt
22/08/2005 14:33 0 YFILE.txt
22/08/2005 14:34 0 ZFILE.txt
6 File(s) 2,089 bytes
2 Dir(s) 21,488,177,152 bytes free

E:\MAPPED\TESTING>





Dean Wells said:
I can only assume by alphabetically less than 'G' that you're
referring to the first character of the filename? If so, no, not
natively ... though it can be scripted ... the enclosed file
achieves precisely that (it is enclosed as, when pasted and posted,
the script becomes too fragmented and awkward to reconstruct). The
file has been renamed to a text file and needs its extension changed
to .BAT or .CMD. Should the enclosure be inaccessible to you,
please post back.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l

Ben said:
Is it possible to issue a DEL command which deletes files based on
an alpabetical less than or greater than?

Basically as follows: (delete all files which are alphabetically
less than "G" for example)
C:> DEL < G*.*
or
C:> DEL [a-f]*.*

Anythig like that exist?

Thanks,
 
PS - Jerold's solution will probably work well for the newer objective,
simply replace the 'G' within his script with the value that the
filenames must be less than ... please test it first by replacing the
'del' command with 'echo del'.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l

Ben said:
Hi Dean, I couldn't get the command working. See the command prompt
output below

Also, I actualy simplified the scenario in my original post, I
actually want to delete files which are named with a date prefix:
i.e. 20050105_EXPORT.zip and so on.. I want to be able to delete
files which are dated older than 14 days. So the first letter isn't
quite enough for what I am looking for.

I can easily produce the date part of the command via the SQL tool
(i.e "del 20050105_EXPORT.zip") so if today is 20050822, I can easily
produce "del 20050807*.zip" but it's the less than part I can't do...

[from command prompt window]
E:\MAPPED\TESTING>DIR
Volume in drive E is DATA
Volume Serial Number is F034-FCD8

Directory of E:\MAPPED\TESTING

22/08/2005 14:44 <DIR> .
22/08/2005 14:44 <DIR> ..
22/08/2005 14:33 0 AFILE.txt
22/08/2005 14:34 2,089 alphacmd.BAT
22/08/2005 14:33 0 BFILE.txt
22/08/2005 14:33 0 GFILE.txt
22/08/2005 14:33 0 YFILE.txt
22/08/2005 14:34 0 ZFILE.txt
6 File(s) 2,089 bytes
2 Dir(s) 21,488,177,152 bytes free

E:\MAPPED\TESTING>ALPHACMD G

Working ...

del a /-p
del b /-p
del c /-p
del d /-p
del e /-p
del f /-p
del G /-p

E:\MAPPED\TESTING>DIR
Volume in drive E is DATA
Volume Serial Number is F034-FCD8

Directory of E:\MAPPED\TESTING

22/08/2005 14:44 <DIR> .
22/08/2005 14:44 <DIR> ..
22/08/2005 14:33 0 AFILE.txt
22/08/2005 14:34 2,089 alphacmd.BAT
22/08/2005 14:33 0 BFILE.txt
22/08/2005 14:33 0 GFILE.txt
22/08/2005 14:33 0 YFILE.txt
22/08/2005 14:34 0 ZFILE.txt
6 File(s) 2,089 bytes
2 Dir(s) 21,488,177,152 bytes free

E:\MAPPED\TESTING>





Dean Wells said:
I can only assume by alphabetically less than 'G' that you're
referring to the first character of the filename? If so, no, not
natively ... though it can be scripted ... the enclosed file
achieves precisely that (it is enclosed as, when pasted and posted,
the script becomes too fragmented and awkward to reconstruct). The
file has been renamed to a text file and needs its extension changed
to .BAT or .CMD. Should the enclosure be inaccessible to you,
please post back.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l

Ben said:
Is it possible to issue a DEL command which deletes files based on
an alpabetical less than or greater than?

Basically as follows: (delete all files which are alphabetically
less than "G" for example)
C:> DEL < G*.*
or
C:> DEL [a-f]*.*

Anythig like that exist?

Thanks,
 
Ben Rum said:
Hi Dean, I couldn't get the command working. See the command prompt output
below

Also, I actualy simplified the scenario in my original post, I actually
want
to delete files which are named with a date prefix: i.e.
20050105_EXPORT.zip
and so on.. I want to be able to delete files which are dated older than
14
days. So the first letter isn't quite enough for what I am looking for.

I can easily produce the date part of the command via the SQL tool (i.e
"del
20050105_EXPORT.zip") so if today is 20050822, I can easily produce "del
20050807*.zip" but it's the less than part I can't do...

If you actually require to delete files older than 14 days, try looking in
alt.msdos.batch.nt where this problem has been solved and published a number
of times.

HTH

....Bill
 
Back
Top