AB~~~~~XYZ~~.txt
means: 2 first letters are AB
3 letters on position 8-10 are XYZ
~ any characters
Any idea?
@echo off
setlocal
set "pattern=ab.....xyz*"
for /f %%i in ('dir /b' ^| findstr /i "%pattern%") do del "%%i"
And try:
del ab?????xyz??.txt
But I am afraid of this variant. In some cases "?" is not works as you
think.
? = any single character
What's so hard about that?
--
It is not the end. It is not the beginning of the end.
It is the end of the beginning.
On Wed, 19 Jan 2011 07:34:31 -0800 (PST), 01MDM <001.d...@gmail.com>
wrote:
The fact that ?? matches both _one_ and two characters. Try to match two
characters only, and you'll face the small dilemma.
All the best, Timo
--
Prof. Timo Salmi mailto:t...@uwasa.fi ftp & http://garbo.uwasa.fi/
Hpage: http://www.uwasa.fi/laskentatoimi/english/personnel/salmitimo/
Department of Accounting and Finance, University of Vaasa, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip
> On 19.01.2011 18:24 Auric__ <not.m...@email.address> wrote:
>> ? = any single character
>> What's so hard about that?
>
> The fact that ?? matches both _one_ and two characters. Try to match two
> characters only, and you'll face the small dilemma.
I'd call that a bug. Sigh.
I'm used to my home machine (Linux), where (for example) "???????" matches
"encrypt" and "decrypt" but not "list" or "updateIP".
--
Darwin is hard at work.
>AB~~~~~XYZ~~.txt
>Any idea?
You can try these ways:
This way it does not matter how many charactors are in the file name.
del AB*XYZ**.txt
This way it should delete the files with the number of charactors that
are in the file name.
del AB?????XYZ??.txt
Another way to delete is echo y | del *.*
Since this is the batch.nt you can use switches with del but I never
end up doing so out of habbit...
http://www.filegod.netfirms.com/Bats
Huh, I guess I was wrong del AB?????XYZ??.txt would work on files
named del ABXYZ.txt also.
I did find that if I just want to list the long file names in a
directory I got them to list like this:
dir/x *~*.*
Try it with a file called ABC~.TXT
--
Regards,
Mic
>Try it with a file called ABC~.TXT
It looks like ABC~.TXT needs to be changed to ABC~*.TXT but the /x switch
is not needed after all to get the long file names like this:
dir *~*.*
I think I want to see if I can find another command interpreter that
will do more stuff than cmd.exe or command.com that will do things like
Visual Basic & C++ can do such as Left, Right, Mid...
Oh Mic, you literly meant a file named ABC~.TXT, I have never
seen a file with a Tilde actually in the file name, I just found
my FilesBBS.cmd does not handle files with the symbol "!" in the
file name, dang, just when you think ya got all the bugs fixed =8-O
I don't recall seeing a trailing tilde like that, but I often prefix a
filename with them when I want a file to be displayed at the top of the list
in Explorer.
Yeah, today is the first time I have ever named a file with a tilde in it
but it was just for testing a batch file, in one of the programs I wrote
it has a form to suggest a file name, it removes exclanation points,
colons, commas & stuff like that, I guess I will add tilde to it...
For a similar job, consider (tested)
dir /b | mtr -ox+ ^^(......\.txt)$ = "del \1" > $$$.bat
then check $$$.bat, and if OK then execute and delete it. MiniTrue
(mtr) there finds, using RegExp notation, only lines containing only six
characters dot t x t, and outputs those lines with "del " in front.
So probably you want the argument ^^(AB.....XYZ\.txt)$ instead.
If case matters, use -c-.
The advantages of the approach are that MiniTrue can do quite general
editing, and that you can test the selection and editing without any
risk of execution, and that MiniTrue can also be used as a file viewer
or programmed editor.
--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 8.
Web <http://www.merlyn.demon.co.uk/> - FAQ-type topics, acronyms, and links.
Command-prompt MiniTrue is useful for viewing/searching/altering files. Free,
DOS/Win/UNIX now 2.0.6; see <URL:http://www.merlyn.demon.co.uk/pc-links.htm>.
In Windows XP, and AFAIR in Windows 98, and so probably in others, any
file which has a name that does not fit within the traditional 8.3
pattern also has a name which does, and that name (always?) contains a
tilde.
So, for example, my file 404.HTML has an alias 404~1.HTM,
and
>dir 4*~*.* /od /b
-> 404.HTML
When the abbreviated name is created, there is a check that it is not
already in use. But I don't know whether there is a corresponding check
when an 8.3 name containing a tilde is created - there should be.
It seems rather unwise, therefore, to have both filenames containing
tilde and wildcards in use, since the unexpected might happen. Granted,
I only recall seeing an auto-tilde in position 7, but I have a vague
recollection that the long-to-short name algorithm may do more than that
in awkward situations.
These files were all generated in turn on the indicated dates, without
editing or relevant deletions, on one copy of WinXP, by one program :
>HUNT *.txt * h~ e | sort
2006/12/21-10:46:02 ADDRS_~1.TXT 3984 .....a..
2008/11/14-16:30:22 ADDRS_~2.TXT 36082 .....a..
2009/11/12-12:44:48 ADDRS_~3.TXT 50882 .....a..
2009/12/20-18:02:46 ADDRS_~4.TXT 51546 .....a..
2010/05/15-21:37:34 ADC6D3~1.TXT 56979 .....a..
2010/06/21-18:34:30 ADCAD3~1.TXT 58412 .....a..
2011/01/17-16:42:08 ADCED3~1.TXT 66632 .....a..
>dir /o:d add*.txt
...
2006-12-21 10:46 3,984 addrs_001.txt
2008-11-14 16:30 36,082 addrs_002.txt
2009-11-12 12:44 50,882 addrs_003.txt
2009-12-20 18:02 51,546 addrs_004.txt
2010-05-15 21:37 56,979 addrs_005.txt
2010-06-21 18:34 58,412 addrs_006.txt
2011-01-17 16:42 66,632 addrs_007.txt
...
Note that those are clearly the same 7 files, but the name-munging
algorithm clearly changed, apparently during the life of XP sp2.
--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk DOS 3.3 6.20 ; WinXP.
Web <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.
I can see no basis for that claim. AFAIAA, ...1-4 are created and then the
algorithm gets bored and tries something new, regardless of XP version -
don't have 98 machine currently available for testing...
for instance,
for /l %i in (1,1,7) do dir > addrs_00%i.txt
creates:
23/01/11 09:10 67,910 ADDRS_~1.TXT addrs_001.txt
23/01/11 09:10 67,959 ADDRS_~2.TXT addrs_002.txt
23/01/11 09:10 68,008 ADDRS_~3.TXT addrs_003.txt
23/01/11 09:10 68,057 ADDRS_~4.TXT addrs_004.txt
23/01/11 09:10 68,106 ADC6D3~1.TXT addrs_005.txt
23/01/11 09:10 68,155 ADCAD3~1.TXT addrs_006.txt
23/01/11 09:10 68,204 ADCED3~1.TXT addrs_007.txt
so - precisely the same names.
And if ADDRS_~3.TXT already exists (for instance)
23/01/11 09:19 68,004 ADDRS_~1.TXT addrs_001.txt
23/01/11 09:19 68,053 ADDRS_~2.TXT addrs_002.txt
23/01/11 09:19 68,102 ADDRS_~4.TXT addrs_003.txt
23/01/11 09:19 68,151 ADC2D3~1.TXT addrs_004.txt
23/01/11 09:19 68,200 ADC6D3~1.TXT addrs_005.txt
23/01/11 09:19 68,249 ADCAD3~1.TXT addrs_006.txt
23/01/11 09:19 68,298 ADCED3~1.TXT addrs_007.txt
23/01/11 09:11 623 ADDRS_~3.TXT
So empirically, the 8.3 filename is generated from the first 6 characters of
the LFN, converted to upper-case plus a tilde, then 1..4 and the first 3
characters of the extent, converted to upper-case; provided the name doesn't
already exist. Thereafter, the algorithm tries the first 2 characters+4
characters which appear to be the hex of two bytes + ~1.first 3 of extent
It appears that the 8.3 name for this second approach is derived from the
original filename as the same sequence always appears for any particular
name; noting also that the fourth character increases by 4 for each
candidate name - when there is an existing file, the starting point appears
to have been increased by 4 1 fewer time (ADC2.. for _004 with _003 already
existing; ADC6.. for _005 regardless)
If _~1.._~4 already exist, we get
23/01/11 09:46 68,148 ADC6C3~1.TXT addrs_001.txt
23/01/11 09:46 68,197 ADCAC3~1.TXT addrs_002.txt
23/01/11 09:46 68,246 ADCEC3~1.TXT addrs_003.txt
23/01/11 09:46 68,295 ADC2D3~1.TXT addrs_004.txt
23/01/11 09:46 68,344 ADC6D3~1.TXT addrs_005.txt
23/01/11 09:46 68,393 ADCAD3~1.TXT addrs_006.txt
23/01/11 09:46 68,442 ADCED3~1.TXT addrs_007.txt
23/01/11 09:20 684 ADDRS_~1.TXT
23/01/11 09:20 684 ADDRS_~2.TXT
23/01/11 09:20 684 ADDRS_~3.TXT
23/01/11 09:20 684 ADDRS_~4.TXT
I believe that I've seen a Microsoft explanation of precisely how the name
is generated, but I no longer have the reference.
The files like AB~~~~~XYZ~~.txt I want to delete
but not AB~~~XYZ~~.txt
Thank you
Oops - seems we've lost the original problem in quibbling about technique...
(but please, Yogi - follow group protocol and end-post - comments added at
the END, not at the start...)
Given a directory:
23/01/11 17:03 782 AB1 3 5XYZ 2.txt
23/01/11 17:02 730 AB1 3 5XYZ12.txt
23/01/11 17:12 834 AB1%3 5XYZ12.txt
23/01/11 17:12 886 AB1%3!5XYZ12.txt
23/01/11 17:13 938 AB1%3%5XYZ12.txt
23/01/11 17:02 626 AB12345XYQ12.txt
23/01/11 17:01 365 AB12345XYZ12.txt
23/01/11 17:01 471 AB12345XYZ123.txt
23/01/11 17:02 522 AB1234XYZ12.txt
23/01/11 17:02 574 AB1234XYZ123.txt
23/01/11 17:01 418 AB12345XYZ12.txtx
23/01/11 17:02 678 QB12345XYZ12.txt
Here's a simple way:
This solution developed using XP
It may work for NT4/2K
----- batch begins -------
[1]@echo off
[2]for /f "delims=" %%i in ( ' dir /a-d /b ' ) do set filename=%%i&call
:seldel
[3]goto :eof
[4]
[5]:: Selective delete
[6]:seldel
[7]if /i "%filename:~0,2%"=="AB" if /i "%filename:~7,3%"=="XYZ" if
"%filename:~12,4%"==".txt" if "%filename:~16%"=="" ECHO del "%filename%"
[8]goto :eof
------ batch ends --------
Lines start [number] - any lines not starting [number] have been wrapped and
should be rejoined. The [number] that starts the line should be removed
The ECHO keyword needs to be removed to activate the rename/delete It is
there as a safety measure to show what the process WOULD do until you have
verified that it will do what you require
The label :eof is defined in NT+ to be end-of-file but MUST be expressed as
:eof
The spaces surrounding the single-quotes are for emphasis only. The SPACES
are not required but the single-quotes ARE required.
Note that in [7], the "/i" makes the matching case-INsensitive, so the match
on "AB" and "XYZ" - case doesn't matter; .txt case DOES matter because the
/i has been omitted
The substring syntax is :~begincolumn-1,length
mix and match as you see fit.
The result of this batch is
del "AB1 3 5XYZ 2.txt"
del "AB1 3 5XYZ12.txt"
del "AB1%3 5XYZ12.txt"
del "AB1%3!5XYZ12.txt"
del "AB1%3%5XYZ12.txt"
del "AB12345XYZ12.txt"
remember, to actually delete the files, you need to remove the ECHO keyword
from [7]
Here's the same basic formula in different forms:
----- batch begins -------
[1]@echo off
[2]for /f "delims=" %%i in ( ' dir /a-d /b ' ) do set filename=%%i&call
:seldel
[3]echo another way
[4]for /f "delims=" %%i in ( ' dir /a-d /b ' ) do set filename=%%i&call
:seldel2
[5]echo and another way
[6]for /f "delims=" %%i in ( ' dir /a-d /b ' ) do set filename=%%i&call
:seldel3&if not defined filename ECHO del "%%i"
[7]goto :eof
[8]
[9]:: Selective delete
[10]:seldel
[11]if /i "%filename:~0,2%"=="AB" if /i "%filename:~7,3%"=="XYZ" if
"%filename:~12,4%"==".txt" if "%filename:~16%"=="" ECHO del "%filename%"
[12]goto :eof
[13]
[14]:: Selective delete #2
[15]:seldel2
[16]if /i NOT "%filename:~0,2%"=="AB" goto :eof
[17]if /i NOT "%filename:~7,3%"=="XYZ" goto :eof
[18]if NOT "%filename:~12,4%"==".txt" goto :eof
[19]if "%filename:~16%"=="" ECHO del "%filename%"
[20]goto :eof
[21]
[22]:: Selective delete #3 - by setting/clearing a flag
[23]:seldel3
[24]if /i NOT "%filename:~0,2%"=="AB" goto :eof
[25]if /i NOT "%filename:~7,3%"=="XYZ" goto :eof
[26]if NOT "%filename:~12,4%"==".txt" goto :eof
[27]if "%filename:~16%"=="" (set filename=)
[28]goto :eof
------ batch ends --------
note that [6] sets the variable FILENAME for each filename, but [27] removes
the variable from the environment, so if ALL of the matches are true, the
variable FILENAME does NOT exist in the environment when SELDEL3 returns.
The result of running this batch is:
del "AB1 3 5XYZ 2.txt"
del "AB1 3 5XYZ12.txt"
del "AB1%3 5XYZ12.txt"
del "AB1%3!5XYZ12.txt"
del "AB1%3%5XYZ12.txt"
del "AB12345XYZ12.txt"
another way
del "AB1 3 5XYZ 2.txt"
del "AB1 3 5XYZ12.txt"
del "AB1%3 5XYZ12.txt"
del "AB1%3!5XYZ12.txt"
del "AB1%3%5XYZ12.txt"
del "AB12345XYZ12.txt"
and another way
del "AB1 3 5XYZ 2.txt"
del "AB1 3 5XYZ12.txt"
del "AB1%3 5XYZ12.txt"
del "AB1%3!5XYZ12.txt"
del "AB1%3%5XYZ12.txt"
del "AB12345XYZ12.txt"
This uses GNUSED
@echo off
dir AB*XYZ*.txt /b /s |sed /^AB.....XYZ..\.txt$/I!d >temp.bat
for /f "delims=" %%a in (temp.bat) do echo del "%%a"
del temp.bat
--
Regards,
Mic
I realise that files in any subdirectories won't match the sed regexp in
this version but you can probably alter that.
--
Regards,
Mic
Either way, one can only conclude that Microsoft has failed to correct the
combined convention issue. It would seem simple to default to using one
naming convention (8.3) or the other (LFN) and just add a switch to choose
the opposite convention. In Win95/98/ME the LFNFOR command was provided to
switch FOR.IN.DO command between 8.3 and LFN convention. For whatever
reason, that provision was excluded in the NT/2X/XP/7 line. ISTM, with the
number of updates that Microsoft imposes on us daily, they have certainly
fallen down in correcting this bug (ahem..feature) over the past 16 years.
:(
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Wait a minute. In XP it doesn't match the file if the number of ? is wrong.
How do you produce that bug?
--
Reply in group, but if emailing add one more
zero, and remove the last word.
--
Zaphod
Arthur: All my life I've had this strange feeling that there's
something big and sinister going on in the world.
Slartibartfast: No, that's perfectly normal paranoia. Everyone in the
universe gets that.
I can confirm that.
D:\>dir ????????.??? /b
A.BAT
hybrid.bat
D:\>dir /b
A.BAT
hybrid.bat
--
Regards,
Mic
D:\temp>dir /b
err.cmd
ethermac.bat
ethermacIP.bat
filexist.bat
log.txt
macaddress.txt
tz.reg
windowsupdate.bat
testfilewithlong.extension
D:\temp>dir ????????.??? /b
err.cmd
ethermac.bat
ethermacIP.bat
filexist.bat
log.txt
macaddress.txt
tz.reg
windowsupdate.bat
testfilewithlong.extension
Notice that even files with long file names that have more than 8
characters in the file name and more than 3 characters in the
extension are listed so ISTM it is matching short file names.
--
Zaphod
"The best Bang since the Big One" - Eccentrica Gallumbits
> Auric__ wrote:
>> On Thu, 20 Jan 2011 19:18:09 GMT, "Timo Salmi" wrote:
>>
>> > On 19.01.2011 18:24 Auric__ <not.m...@email.address> wrote:
>> > > ? = any single character
>> > > What's so hard about that?
>> >
>> > The fact that ?? matches both _one_ and two characters. Try to
>> > match two characters only, and you'll face the small dilemma.
>>
>> I'd call that a bug. Sigh.
>>
>> I'm used to my home machine (Linux), where (for example) "???????"
>> matches "encrypt" and "decrypt" but not "list" or "updateIP".
>
> Wait a minute. In XP it doesn't match the file if the number of ? is
> wrong. How do you produce that bug?
Check this out:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Users\Auric\Desktop>dir /b ????.*
dv.txt
3bz.cmd
work
utc.bas
cox.txt
Pd.txt
5to7.bas
5to7.xls
--
I like to skate on the other side of the ice.
-- Steven Wright
> ? = any single character
That is the definition I recall from the late '80s, but in regular
expressions '?' is defined as zero or one of any character. Maybe
MicroSoft has shifted. If so, '??' should match any string of length
0, 1, or 2.
Frank
Ok, with question marks all the way to the end, yes I know. But the OP had
a problem with embedded question marks, like del ab?????xyz??.txt. I didn't
realize you were refering to the last 2 on the end.