extended DIR syntax?

#1
Hi,

C:\> global /i /q for %fn in (*MA[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9].jpg) ren /n "%fn" %@le
ft[-15,%@name["%fn"]].jpg

Is there a way to make sure the MA are both uppercase - besides doing a:

IF @INSTR[start,[length],string] type test on each charachter?
 
#2
[email protected] wrote:
| Hi,
|
| C:\> global /i /q for %fn in
| (*MA[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9].jpg)
| ren /n "%fn" %@le ft[-15,%@name["%fn"]].jpg
|
| Is there a way to make sure the MA are both uppercase - besides
| doing a:
|
| IF @INSTR[start,[length],string] type test on each charachter?

Sorry, no.
--
Steve
 
#3
I had written:

---
Use DIR and a regular expression: DIR /B ::.*MA\d{8}_\d{4}\.(?i)jpg (I think).
You can use the output of the DIR command as FOR's "set".
---

But then I discovered, it seems, that DIR with regexes is not case sensitive
(even though the regex is). See my other, upcoming post.

v:\> for /f "tokens=*" %file in ( 'dir /b ::.*\.bat' ) echo %file
a b c.bat
anagram.bat
bdb.bat
ctrlc.bat
qbat.bat
test.bat

v:\> for /f "tokens=*" %file in ( 'dir /b ::.*\.BAT' ) echo %file
a b c.bat
anagram.bat
bdb.bat
ctrlc.bat
qbat.bat
test.bat

On Sun, 19 Jul 2009 17:05:53 -0500, "[email protected]"
<> wrote:

|Hi,
|
|C:\> global /i /q for %fn in (*MA[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9].jpg) ren /n "%fn" %@le
|ft[-15,%@name["%fn"]].jpg
|
|Is there a way to make sure the MA are both uppercase - besides doing a:
|
|IF @INSTR[start,[length],string] type test on each charachter?
|
|
|
|
|
|
--
- Vince
 
#4
global /i /q (*dir /b
*MA[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9].jpg |
*ffind /c /v /m /k
/T"MA" | for %fn in (@con:) echo ren /n "%fn" %@left[-15,%@name["%fn"]].jpg)

Ugly, but seems to work. Piping through ffind /c is the key for my attempt.

On Sun, Jul 19, 2009 at 3:05 PM,
[email protected]<> wrote:

> Hi,
>
> C:\> global /i /q for %fn in (*MA[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9].jpg) ren /n "%fn" %@le
> ft[-15,%@name["%fn"]].jpg
>
> Is there a way to make sure the MA are both uppercase - besides doing a:
>
> IF @INSTR[start,[length],string] type test on each charachter?
>
>
>
>
>
>
>


--
Jim Cook
2009 Saturdays: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
Next year they're Sunday.
 
#5
Of course, remove the "echo" that I was using for testing.

On Mon, Jul 20, 2009 at 8:27 AM, Jim Cook<[email protected]> wrote:

> global /i /q (*dir /b
> *MA[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9].jpg |
> *ffind /c /v /m /k
> */T"MA" | for %fn in (@con:) echo ren /n "%fn" %@left[-15,%@name["%fn"]].jpg)
>
> Ugly, but seems to work. Piping through ffind /c is the key for my attempt.
>
> On Sun, Jul 19, 2009 at 3:05 PM,
> [email protected]<> wrote:
>> Hi,
>>
>> C:\> global /i /q for %fn in (*MA[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9].jpg) ren /n "%fn" %@le
>> ft[-15,%@name["%fn"]].jpg
>>
>> Is there a way to make sure the MA are both uppercase - besides doing a:
>>
>> IF @INSTR[start,[length],string] type test on each charachter?
>>
>>
>>
>>
>>
>>
>>
>
>
>
> --
> Jim Cook
> 2009 Saturdays: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
> Next year they're Sunday.
>


--
Jim Cook
2009 Saturdays: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
Next year they're Sunday.
 
#6
Jim Cook wrote:
| global /i /q (*dir /b
| *MA[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9].jpg
| |
| *ffind /c /v /m /k
| /T"MA" | for %fn in (@con:) echo ren /n "%fn"
| %@left[-15,%@name["%fn"]].jpg)
|
| Ugly, but seems to work. Piping through ffind /c is the key for my
| attempt.

The only problem is that a filename like zMAzma00000000_0000.jpg matches all
the tests, even though not matching the intended test.

I don't see an alternative to using an IF test using the EQC operator on the
specific characters, something like this:

do fn in /s
*MA[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9].jpg
set n=%@name["%fn"]
if "%@left[2,%@right[15,%n]]" EQC "MA" ren "%fn" %@left[-15,%n]].jpg
enddo

BTW, Charles, are you sure you wanted %@left[-15,%@name["%fn"]], which keeps
the leftmost 15 characters, potentially dropping some of the digits, rather
than %@right[15,%@name["%fn"]] which would strip all characters matching the
* portion of the search string, retaining MA and all digits?
--
Steve
 
#7
I guess it's easier to use ffind to do the whole match, since the
regular expression (/e"...") is case sensitive.

Does this do it?

global /i /q (dir/b | ffind /k /m /v /e"MA\d{8,8}_\d{4,4}\.jpg$" | for
%fn in (@con:) ren /n "%fn" %@left[-15,%@name["%fn"]].jpg)

On Mon, Jul 20, 2009 at 9:29 AM, Steve Fábián<> wrote:

> Jim Cook wrote:
> | global /i /q (*dir /b
> | *MA[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9].jpg
> | |
> | *ffind /c /v /m /k
> | /T"MA" | for %fn in (@con:) echo ren /n "%fn"
> | %@left[-15,%@name["%fn"]].jpg)
> |
> | Ugly, but seems to work. Piping through ffind /c is the key for my
> | attempt.
>
> The only problem is that a filename like zMAzma00000000_0000.jpg matches all
> the tests, even though not matching the intended test.
>
> I don't see an alternative to using an IF test using the EQC operator on the
> specific characters, something like this:
>
> do fn in /s
> *MA[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9].jpg
> *set n=%@name["%fn"]
> *if "%@left[2,%@right[15,%n]]" EQC "MA" ren "%fn" %@left[-15,%n]].jpg
> enddo
>
> BTW, Charles, are you sure you wanted %@left[-15,%@name["%fn"]], which keeps
> the leftmost 15 characters, potentially dropping some of the digits, rather
> than %@right[15,%@name["%fn"]] which would strip all characters matching the
> * portion of the search string, retaining MA and all digits?
> --
> Steve
>
>
>
>
>


--
Jim Cook
2009 Saturdays: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
Next year they're Sunday.
 
#8
----- Original Message -----
From: "Jim Cook" <>
To: <[email protected]>
Sent: Monday, July 20, 2009 06:08 PM
Subject: RE: [Support-t-1245] extended DIR syntax?



>I guess it's easier to use ffind to do the whole match, since the
> regular expression (/e"...") is case sensitive.
>
> Does this do it?
>
> global /i /q (dir/b | ffind /k /m /v /e"MA\d{8,8}_\d{4,4}\.jpg$" | for
> %fn in (@con:) ren /n "%fn" %@left[-15,%@name["%fn"]].jpg)
>
> On Mon, Jul 20, 2009 at 9:29 AM, Steve Fábián<> wrote:
>
>
> ---Quote---
>> Jim Cook wrote:
>> | global /i /q (*dir /b
>> | *MA[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9].jpg
>> | |
>> | *ffind /c /v /m /k
>> | /T"MA" | for %fn in (@con:) echo ren /n "%fn"
>> | %@left[-15,%@name["%fn"]].jpg)
>> |
>> | Ugly, but seems to work. Piping through ffind /c is the key for my
>> | attempt.
>>
>> The only problem is that a filename like zMAzma00000000_0000.jpg matches
>> all
>> the tests, even though not matching the intended test.
>>
>> I don't see an alternative to using an IF test using the EQC operator on
>> the
>> specific characters, something like this:
>>
>> do fn in /s
>> *MA[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9].jpg
>> *set n=%@name["%fn"]
>> *if "%@left[2,%@right[15,%n]]" EQC "MA" ren "%fn" %@left[-15,%n]].jpg
>> enddo
>>
>> BTW, Charles, are you sure you wanted %@left[-15,%@name["%fn"]], which
>> keeps
>> the leftmost 15 characters, potentially dropping some of the digits,
>> rather
>> than %@right[15,%@name["%fn"]] which would strip all characters matching
>> the
>> * portion of the search string, retaining MA and all digits?
Steve, if you notice the %@left[-15,%@name["%fn"]] will actually take all
but the 15 rightmost charachters, due to the minus 15 and not the positive
15. And I had forgotten about the EQC test - thanks. Now it will be easier
to test the two charachters together.


>> --
>> Steve
>>
>>
>>
>>
>>
> ---End Quote---
>
>
> --
> Jim Cook
> 2009 Saturdays: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
> Next year they're Sunday.
>
>
>
>
>