PC Review


Reply
Thread Tools Rate Thread

DEL command help

 
 
Ben Rum
Guest
Posts: n/a
 
      22nd Aug 2005
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,


 
Reply With Quote
 
 
 
 
Jerold Schulman
Guest
Posts: n/a
 
      22nd Aug 2005
On Mon, 22 Aug 2005 12:17:16 +0100, "Ben Rum" <(E-Mail Removed)> wrote:

>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
 
Reply With Quote
 
Dean Wells [MVP]
Guest
Posts: n/a
 
      22nd Aug 2005
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 Schulman wrote:
> On Mon, 22 Aug 2005 12:17:16 +0100, "Ben Rum" <(E-Mail Removed)>
> wrote:
>
>> 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



 
Reply With Quote
 
Ben Rum
Guest
Posts: n/a
 
      22nd Aug 2005

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 [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 Rum wrote:
> > 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,

>
>
>



 
Reply With Quote
 
Dean Wells [MVP]
Guest
Posts: n/a
 
      22nd Aug 2005
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 Rum wrote:
> 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 [MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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 Rum wrote:
>>> 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,



 
Reply With Quote
 
Dean Wells [MVP]
Guest
Posts: n/a
 
      22nd Aug 2005
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 Rum wrote:
> 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 [MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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 Rum wrote:
>>> 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,



 
Reply With Quote
 
billious
Guest
Posts: n/a
 
      23rd Aug 2005

"Ben Rum" <(E-Mail Removed)> wrote in message
news:u%(E-Mail Removed)...
>
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Execute Batch Command Automatically form Command Shell with Minlogon stuie_norris@yahoo.com.au Windows XP Embedded 1 21st May 2010 12:26 PM
Data shape command text contains a syntax error at or near position 106 in the command. Bob Microsoft Access ADP SQL Server 3 14th Apr 2008 09:43 PM
Pivot Table Error Message - "Command Text not set for command obje =?Utf-8?B?SmVmZiBEaXZpYW4=?= Microsoft Excel Misc 0 7th Nov 2007 10:26 PM
autorun.inf - shell\..\command with command line parameter doesn'twork kakii Windows XP Help 1 17th May 2007 08:54 PM
A resource kit command that allows the NET USER command to get info strictly from a specific container or OU =?Utf-8?B?Ym9vNzc3?= Microsoft Windows 2000 Active Directory 3 11th May 2004 08:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:13 PM.