Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

inconsistency of % and !

15 views
Skip to first unread message

Tom Del Rosso

unread,
Dec 18, 2011, 1:27:40 AM12/18/11
to

I wanted to see if any files have % or ! in their names, so I did this and
check errorlevel after each line:

dir /b *%%*.*
dir /b "*^!*.*"

The ! line only works if it's in quotes, and whereas doubling works for the
%, the ! needs an escape.

This is of course with delayedexpansion enabled.

Can someone please explain the logic of this? The inconsistency doesn't
seem logical to me.


--

Reply in group, but if emailing add one more
zero, and remove the last word.


billious

unread,
Dec 18, 2011, 1:46:32 AM12/18/11
to

"Tom Del Rosso" <td...@verizon.net.invalid> wrote in message
news:jck154$n4g$1...@dont-email.me...
Historical issue.

% escaped % from the DOS days.

The special meaning of "!" was introduced with NT, along with "^" being an
escape. This was in addition to the original "%%" which was maintained.

Why not make "^" a universal escape? Only those who write CMD could say with
certainty. Maintaining old batches perhaps - or mechanically translating the
COMMAND method (more likely in my view.)



foxidrive

unread,
Dec 18, 2011, 2:03:55 AM12/18/11
to
On 18/12/2011 17:27, Tom Del Rosso wrote:
> I wanted to see if any files have % or ! in their names, so I did this and
> check errorlevel after each line:
>
> This is of course with delayedexpansion enabled.

FWIW I don't see the need for delayed expansion.


@echo off
for /f "delims=" %%a IN ('dir /a:d /b /s') do (
pushd "%%a"
dir /b *%%* *!* >nul 2>&1 && echo "%%a"
popd
)
pause



I agree with billious that there is history involved.


--
Regards,
Mic

Tom Del Rosso

unread,
Dec 18, 2011, 2:05:38 AM12/18/11
to

billious wrote:
>
> Historical issue.
>
> % escaped % from the DOS days.
>
> The special meaning of "!" was introduced with NT, along with "^"
> being an escape. This was in addition to the original "%%" which was
> maintained.
> Why not make "^" a universal escape? Only those who write CMD could
> say with certainty. Maintaining old batches perhaps - or mechanically
> translating the COMMAND method (more likely in my view.)

Ok, and I guess the quotes aren't needed for the % because that escape is
done at a different stage of the parsing process.

Thanks.

Tom Del Rosso

unread,
Dec 18, 2011, 2:20:20 AM12/18/11
to

foxidrive wrote:
> On 18/12/2011 17:27, Tom Del Rosso wrote:
> > I wanted to see if any files have % or ! in their names, so I did
> > this and check errorlevel after each line:
> >
> > This is of course with delayedexpansion enabled.
>
> FWIW I don't see the need for delayed expansion.

But it's not needed because of the above test. The test is needed because
delayed expansion is enabled for another part of the batch.

BTW why do you use the FOR and PUSHD to recurse directories instead of using
/s on the DIR line?

foxidrive

unread,
Dec 18, 2011, 2:47:11 AM12/18/11
to
On 18/12/2011 18:20, Tom Del Rosso wrote:
> foxidrive wrote:
>> On 18/12/2011 17:27, Tom Del Rosso wrote:
>>> I wanted to see if any files have % or ! in their names, so I did
>>> this and check errorlevel after each line:
>>>
>>> This is of course with delayedexpansion enabled.
>>
>> FWIW I don't see the need for delayed expansion.
>
> But it's not needed because of the above test. The test is needed because
> delayed expansion is enabled for another part of the batch.
>
> BTW why do you use the FOR and PUSHD to recurse directories instead of using
> /s on the DIR line?

Because it will report the branch and the same folder over and over in a deep nested tree.

The method I used will only report the folders with those files.



--
Regards,
Mic

Timo Salmi

unread,
Dec 18, 2011, 3:07:33 AM12/18/11
to
On 18.12.2011 09:03 foxidrive <foxi...@gotcha.woohoo.invalid> wrote:
> On 18/12/2011 17:27, Tom Del Rosso wrote:
>> I wanted to see if any files have % or ! in their names, so I did this and

> @echo off
> for /f "delims=" %%a IN ('dir /a:d /b /s') do (
> pushd "%%a"
> dir /b *%%* *!* >nul 2>&1 && echo "%%a"
> popd
> )
> pause

That code appears to answer a subtly different question. It lists the
folders which have such files within them. Besides the whole issue is
more complicated than it first appears. 1) The question should include &
in the names, if we wish to cover common poison characters. 2) What does
one mean by "name". Is the the whole path, which we wish to check, or
the basename only. 3) Maybe one could or should involve findstr.

All the best, Timo

--
Prof. (emer.) Timo Salmi, Vaasa, Finland
http://www.netikka.net/tsneti/homepage.php
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.php

foxidrive

unread,
Dec 18, 2011, 3:15:20 AM12/18/11
to
On 18/12/2011 19:07, Timo Salmi wrote:
> On 18.12.2011 09:03 foxidrive <foxi...@gotcha.woohoo.invalid> wrote:
>> On 18/12/2011 17:27, Tom Del Rosso wrote:
>>> I wanted to see if any files have % or ! in their names, so I did this and
>
>> @echo off
>> for /f "delims=" %%a IN ('dir /a:d /b /s') do (
>> pushd "%%a"
>> dir /b *%%* *!* >nul 2>&1 && echo "%%a"
>> popd
>> )
>> pause
>
> That code appears to answer a subtly different question. It lists the
> folders which have such files within them.

Well spotted Timo. I assumed one would want to know which folders contain those files.

You've also raised the possibility of the folder names, which can contain those characters in the name too.

> Besides the whole issue is
> more complicated than it first appears. 1) The question should include &
> in the names, if we wish to cover common poison characters. 2) What does
> one mean by "name". Is the the whole path, which we wish to check, or
> the basename only. 3) Maybe one could or should involve findstr.

As I see it, % ! and maybe ^ are the three problems characters in a filespec as & and , ; = etc can be double quoted and handled easily.



--
Regards,
Mic

Timo Salmi

unread,
Dec 18, 2011, 3:17:44 AM12/18/11
to
On 18.12.2011 09:47 foxidrive <foxi...@gotcha.woohoo.invalid> wrote:
> The method I used will only report the folders with those files.

Not completely accurate in the most minute of details. It will report
folders with such files or such (immediate?) subfolders. As I wrote, the
question is more involved than it first appears.

foxidrive

unread,
Dec 18, 2011, 3:22:04 AM12/18/11
to
On 18/12/2011 19:17, Timo Salmi wrote:
> On 18.12.2011 09:47 foxidrive <foxi...@gotcha.woohoo.invalid> wrote:
>> The method I used will only report the folders with those files.
>
> Not completely accurate in the most minute of details. It will report
> folders with such files or such (immediate?) subfolders. As I wrote, the
> question is more involved than it first appears.

Why will it report subfolders?




--
Regards,
Mic

Timo Salmi

unread,
Dec 18, 2011, 3:37:49 AM12/18/11
to
Ah. ... folders with such files or WITH such (immediate?) subfolders

foxidrive

unread,
Dec 18, 2011, 3:50:23 AM12/18/11
to
On 18/12/2011 19:37, Timo Salmi wrote:
> On 18.12.2011 10:22 foxidrive wrote:
>> On 18/12/2011 19:17, Timo Salmi wrote:
>>> On 18.12.2011 09:47 foxidrive <foxi...@gotcha.woohoo.invalid> wrote:
>>>> The method I used will only report the folders with those files.
>>> Not completely accurate in the most minute of details. It will report
>>> folders with such files or such (immediate?) subfolders. As I wrote, the
>>> question is more involved than it first appears.
>>
>> Why will it report subfolders?
>
> Ah. ... folders with such files or WITH such (immediate?) subfolders
>

I think I see your viewpoint - I didn't use /a:-d in the dir command so it will report foldernames with those characters too.



--
Regards,
Mic

Timo Salmi

unread,
Dec 18, 2011, 4:24:51 AM12/18/11
to
On 18.12.2011 10:50 foxidrive wrote:
>> Ah. ... folders with such files or WITH such (immediate?)
>> subfolders

> I think I see your viewpoint - I didn't use /a:-d in the dir command
> so it will report foldernames with those characters too.

So now we have, based on your code

How to list folders which have files (or immediate subfolders) with % !
& or ^ in the names?

@echo off & setlocal enableextensions disabledelayedexpansion
for /f "delims=" %%a in ('dir C:\_M /a:d /b /s') do (
pushd "%%a"
dir /b "*%%*" "*!*" "*&*" "*^*" >nul 2>&1 && echo "%%a"
popd)
endlocal & goto :EOF

The disabledelayedexpansion is needed, since else error situations can
arise.

All the best, Timo

--
Prof. (emer.) Timo Salmi, Vaasa, Finland
https://twitter.com/TimoSalmi

foxidrive

unread,
Dec 18, 2011, 6:51:44 AM12/18/11
to
On 18/12/2011 20:24, Timo Salmi wrote:

> So now we have, based on your code


How to list folders which have files with % ! & or ^ in the names

It needs the /a:-d in the dir /b line so that foldernames aren't included and I altered the scope of the batch file to the entire current drive


@echo off & setlocal enableextensions disabledelayedexpansion
for /f "delims=" %%a in ('dir \ /a:d /b /s') do (
pushd "%%a"
dir /b /a:-d "*%%*" "*!*" "*&*" "*^*" >nul 2>&1 && echo "%%a"
popd)
endlocal & goto :EOF


and this should do the same for the directories, as you suggested with findstr


@echo off
setlocal enableextensions disabledelayedexpansion
dir \ /a:d /b /s | findstr /c:"%" /c:"!" /c:"&" /c:"^"
endlocal
goto :EOF




--
Regards,
Mic

Timo Salmi

unread,
Dec 18, 2011, 8:47:35 AM12/18/11
to
On 18.12.2011 13:51 foxidrive wrote:
> On 18/12/2011 20:24, Timo Salmi wrote:
>> So now we have, based on your code

> How to list folders which have files with % ! & or ^ in the names

> and this should do the same for the directories, as you suggested with findstr

I sense a new FAQ item to the collection in the making. Thanks. To the
OP as well.

foxidrive

unread,
Dec 18, 2011, 9:18:53 AM12/18/11
to
On 19/12/2011 00:47, Timo Salmi wrote:
> On 18.12.2011 13:51 foxidrive wrote:
>> On 18/12/2011 20:24, Timo Salmi wrote:
>>> So now we have, based on your code
>
>> How to list folders which have files with % ! & or ^ in the names
>
>> and this should do the same for the directories, as you suggested with findstr
>
> I sense a new FAQ item to the collection in the making. Thanks. To the
> OP as well.

Your welcome. A nice little diversion for us all.


I wanted to say that the directory list code as posted will quite probably repeat folders many times, but I can't see a simple solution.

For example this single folder will also echo the child folders that do not have the problem character.

c:\program files\one & two
c:\program files\one & two\data
c:\program files\one & two\cache
c:\program files\one & two\cache\abc
c:\program files\one & two\cache\def
c:\program files\one & two\cache\ghi
c:\program files\one & two\cache\jkl




--
Regards,
Mic

Timo Salmi

unread,
Dec 18, 2011, 9:28:01 AM12/18/11
to
On 18.12.2011 16:18 foxidrive wrote:

> For example this single folder will also echo the child folders that
> do not have the problem character.

> c:\program files\one & two
> c:\program files\one & two\cache
> c:\program files\one & two\cache\abc
> c:\program files\one & two\cache\def

Yes. That's exactly why I wrote earlier "... the whole issue is
more complicated than it first appears." and "What does one mean by
'name'. Is the the whole path, which we wish to check, or the basename
only."


Tom Del Rosso

unread,
Dec 18, 2011, 9:50:20 AM12/18/11
to

Timo Salmi wrote:
>
> That code appears to answer a subtly different question. It lists the
> folders which have such files within them. Besides the whole issue is
> more complicated than it first appears. 1) The question should
> include & in the names, if we wish to cover common poison characters.

True, and any non-ANSI character is also poison. DIR replaces them with
ANSI equivalents, and if the DIR output is used to point to the file, the
file is not found. Worse yet, there might be two files with the ANSI and
non-ANSI character, so the DIR output for both will point to the same one.

If there is no second file, then this will detect them and open the folder
so it can be renamed manually. I'm not sure how to detect if there is
another file with the ANSI equivalent.

This is from a few years ago. I should have commented it, because I don't
remember why I included the line
if exist "%%~dpf\" (


@echo off
rem find files with non-ANSI chars in their names
rem indicated by size %%~zf being a null string
rem due to the fact that %%f does not match the file name

set "dircmd="
for %%d in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
if exist %%d:\ (
echo Searching %%d:
for /f "delims=" %%f in ('dir %%d:\ /b /s /a') do (
if "%%~zf"=="" (
if exist "%%~dpf\" (
echo "%%f"|findstr /i ":\recycler\ :\recycled\ :\pagefile.sys
:\hiberfil.sys" >nul
if errorlevel 1 (
echo;
echo "%%f"
%SystemRoot%\explorer.exe /n,/e,"%%~dpf"
pause
echo/
echo Continuing search of %%d:
echo/
)
)
)
)
)
)
pause

foxidrive

unread,
Dec 18, 2011, 10:00:39 AM12/18/11
to
On 19/12/2011 01:50, Tom Del Rosso wrote:
> Timo Salmi wrote:
>>
>> That code appears to answer a subtly different question. It lists the
>> folders which have such files within them. Besides the whole issue is
>> more complicated than it first appears. 1) The question should
>> include & in the names, if we wish to cover common poison characters.
>
> True, and any non-ANSI character is also poison. DIR replaces them with
> ANSI equivalents, and if the DIR output is used to point to the file, the
> file is not found. Worse yet, there might be two files with the ANSI and
> non-ANSI character, so the DIR output for both will point to the same one.
>
> If there is no second file, then this will detect them and open the folder
> so it can be renamed manually. I'm not sure how to detect if there is
> another file with the ANSI equivalent.
>
> This is from a few years ago. I should have commented it, because I don't
> remember why I included the line
> if exist "%%~dpf\" (

It makes it only process folders AFAICS. Your DIR command returns files and folders.
Regards,
Mic

foxidrive

unread,
Dec 18, 2011, 10:03:11 AM12/18/11
to
On 19/12/2011 02:00, foxidrive wrote:
> On 19/12/2011 01:50, Tom Del Rosso wrote:
>> Timo Salmi wrote:
>>>
>>> That code appears to answer a subtly different question. It lists the
>>> folders which have such files within them. Besides the whole issue is
>>> more complicated than it first appears. 1) The question should
>>> include & in the names, if we wish to cover common poison characters.
>>
>> True, and any non-ANSI character is also poison. DIR replaces them with
>> ANSI equivalents, and if the DIR output is used to point to the file, the
>> file is not found. Worse yet, there might be two files with the ANSI and
>> non-ANSI character, so the DIR output for both will point to the same one.
>>
>> If there is no second file, then this will detect them and open the folder
>> so it can be renamed manually. I'm not sure how to detect if there is
>> another file with the ANSI equivalent.
>>
>> This is from a few years ago. I should have commented it, because I don't
>> remember why I included the line
>> if exist "%%~dpf\" (
>
> It makes it only process folders AFAICS. Your DIR command returns files and folders.

Maybe I posted in haste. %%~dpf\ will only exist if that path contains ANSI characters, right?

Timo Salmi

unread,
Dec 18, 2011, 12:28:34 PM12/18/11
to
On 18.12.2011 13:51 foxidrive wrote:
> How to list folders which have files with % ! & or ^ in the names

> It needs the /a:-d in the dir /b line so that foldernames aren't
> included and I altered the scope of the batch file to the entire
> current drive
> @echo off & setlocal enableextensions disabledelayedexpansion
> for /f "delims=" %%a in ('dir \ /a:d /b /s') do (
> pushd "%%a"
> dir /b /a:-d "*%%*" "*!*" "*&*" "*^*" >nul 2>&1 && echo "%%a"
> popd)
> endlocal & goto :EOF

Browsing the top folder can be added separately lest it is skipped.

@echo off & setlocal enableextensions disabledelayedexpansion
set top_=C:
dir /b /a:-d "%top_%\*%%*" "%top_%\*!*" "%top_%\*&*" "%top_%\*^*"
>nul 2>&1 && echo %top_%
for /f "delims=" %%a in ('dir "%top_%\" /a:d /b /s') do (
pushd "%%a"
dir /b /a:-d "*%%*" "*!*" "*&*" "*^*" >nul 2>&1 && echo %%a
popd)
endlocal & goto :EOF

Timo Salmi

unread,
Dec 18, 2011, 1:09:13 PM12/18/11
to
On 18.12.2011 13:51 foxidrive wrote:
> @echo off
> setlocal enableextensions disabledelayedexpansion
> dir \ /a:d /b /s | findstr /c:"%" /c:"!" /c:"&" /c:"^"
> endlocal
> goto :EOF

% needs escaping: /c:"%%"

Tom Del Rosso

unread,
Dec 18, 2011, 4:26:35 PM12/18/11
to

foxidrive wrote:
>
> Maybe I posted in haste. %%~dpf\ will only exist if that path
> contains ANSI characters, right?

Right, it actually does a more thorough search without that line. Without
that line it will fail to open the folder, but at least it tells you it
exists.

jeb

unread,
Dec 18, 2011, 5:46:50 PM12/18/11
to
On 18 Dez., 08:05, "Tom Del Rosso" <td...@verizon.net.invalid> wrote:
> billious wrote:
>
> > Historical issue.
>
> > % escaped % from the DOS days.
>
> > The special meaning of "!" was introduced with NT, along with "^"
> > being an escape. This was in addition to the original "%%" which was
> > maintained.
> > Why not make "^" a universal escape? Only those who write CMD could
> > say with certainty. Maintaining old batches perhaps - or mechanically
> > translating the COMMAND method (more likely in my view.)
>
> Ok, and I guess the quotes aren't needed for the % because that escape is
> done at a different stage of the parsing process.

Yes, that's the cause.
The percent signs are replaced in the first phase of the parsing
process,
in this phase the carets ^ haven't any special meaning.
The next phase is the special character phase, it handles quoting,
caret escapes, ampersand and so on.
If you enable delayed expansion there is a further phase at the end,
the exlamation phase.
It has also an escape character, and it is also the caret, but all
other characters are normal, so you can't quote the caret here, and
the caret is used only to esapce an other caret or the exclamation
mark.

Setlocal EnableDelayedExpansion
echo One caret ^^^ and in quotes "^^" and Boom^^!
echo He say "Boom^!"
echo But without exclam, the last phase is ignored - one caret ^^ and
in quotes "^"

Btw there is another caret effect, the CALL command double all carets,
but normally you didn't see this, as they are reduced once more in the
special character phase.
But try
call call call call call echo Hello "^"

For a complete description of the batch parser you could look at
http://stackoverflow.com/a/4095133/463115

Regards
jeb

Todd Vargo

unread,
Dec 18, 2011, 9:06:06 PM12/18/11
to
On 12/18/2011 9:18 AM, foxidrive wrote:
> On 19/12/2011 00:47, Timo Salmi wrote:
>> On 18.12.2011 13:51 foxidrive wrote:
>>> On 18/12/2011 20:24, Timo Salmi wrote:
>>>> So now we have, based on your code
>>
>>> How to list folders which have files with % !& or ^ in the names
>>
>>> and this should do the same for the directories, as you suggested with findstr
>>
>> I sense a new FAQ item to the collection in the making. Thanks. To the
>> OP as well.
>
> Your welcome. A nice little diversion for us all.
>
>
> I wanted to say that the directory list code as posted will quite probably repeat folders many times, but I can't see a simple solution.
>
> For example this single folder will also echo the child folders that do not have the problem character.
>
> c:\program files\one& two
> c:\program files\one& two\data
> c:\program files\one& two\cache
> c:\program files\one& two\cache\abc
> c:\program files\one& two\cache\def
> c:\program files\one& two\cache\ghi
> c:\program files\one& two\cache\jkl

Examine basename.ext only, not the full path.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

foxidrive

unread,
Dec 18, 2011, 9:49:29 PM12/18/11
to
On 19/12/2011 13:06, Todd Vargo wrote:
> On 12/18/2011 9:18 AM, foxidrive wrote:
>> On 19/12/2011 00:47, Timo Salmi wrote:
>>> On 18.12.2011 13:51 foxidrive wrote:
>>>> On 18/12/2011 20:24, Timo Salmi wrote:
>>>>> So now we have, based on your code
>>>
>>>> How to list folders which have files with % !& or ^ in the names
>>>
>>>> and this should do the same for the directories, as you suggested with findstr
>>
>> For example this single folder will also echo the child folders that do not have the problem character.
>>
>> c:\program files\one& two
>> c:\program files\one& two\cache
>> c:\program files\one& two\cache\abc
>> c:\program files\one& two\cache\def
>> c:\program files\one& two\cache\ghi
>> c:\program files\one& two\cache\jkl
>
> Examine basename.ext only, not the full path.

Thank you Todd. That's the ticket!

This should work then...


@echo off & setlocal enableextensions disabledelayedexpansion
for /f "delims=" %%a in ('dir \ /a:d /b /s') do (
echo "%%~nxa"| findstr /c:"%%" /c:"!" /c:"&" /c:"^" >nul && (
echo %%a
)
)
endlocal & goto :EOF




--
Regards,
Mic

Tom Del Rosso

unread,
Dec 18, 2011, 9:45:14 PM12/18/11
to
Thanks for all that Jeb!

Frank P. Westlake

unread,
Dec 19, 2011, 1:25:01 PM12/19/11
to
Your original question was answered but it appears that this thread has
turned into a general discussion on finding and possibly renaming files
with special characters in the name. Here is a script which seems to
function properly in doing that. It deals only with individual
components of the name; checking first file names, then directory names
if configured to, then descends into subdirectories if configured to do so.

The script begins at the directory specified in the variable "$root"
which can be changed to take a path from the command line. It changes to
this directory and deals only with that level of the path. If configured
to descend it will again read the directory to make sure it gets any
changed names.

This script is also available at <https://gist.github.com/1497826>.

@Echo OFF
::EnableDelayedExpansion just to show that we can.
SetLocal EnableExtensions EnableDelayedExpansion
For /F "tokens=1 delims==" %%a in ('Set "$" 2^>NUL:') Do (
Set "%%a="
)
:: For demo:
Set "$RENAME=Echo Rename"
:: For real:
Set "$RENAME=Rename"
:: Begin here:
Set "$root=%TEMP%"
::Set "$root=%*"
Set "$level=3"
:: $verbose: If DEFINED prints current directory.
::Set "$verbose=1"
ChDir /D %$root%
if DEFINED $verbose ChDir
Call :renameBadComponents
Goto :EOF

:renameBadComponents directory
SetLocal EnableExtensions DisableDelayedExpansion
:: First files:
If "%$level%" LSS "1" Goto :EOF
For /F "delims=" %%a in ('DIR /b /a-d 2^>NUL:') Do (
Set "$current=%%a"
Call :changeEXCAMP
Call :changePER
Call :checkAndRename
)
:: Second directories:
If "%$level%" LSS "2" Goto :EOF
For /F "delims=" %%a in ('DIR /b /ad 2^>NUL:') Do (
Set "$current=%%a"
Call :changeEXCAMP
Call :changePER
Call :checkAndRename
)
:: Third descend into subdirectories:
If "%$level%" LSS "3" Goto :EOF
For /F "delims=" %%a in ('DIR /b /ad 2^>NUL:') Do (
SetLocal
ChDir %%a
If DEFINED $verbose ChDir
Call :renameBadComponents
EndLocal
)
Goto :EOF
:changeEXCAMP
Set "$changed=%$current:!=-EXC-%"
Set "$changed=%$changed:&=-AMP-%"
Goto :EOF
:changePER
SetLocal EnableExtensions EnableDelayedExpansion
Set "$changed=!$changed:%%=-PER-!"
EndLocal & Set "$changed=%$changed%" & Goto :EOF
:checkAndRename
SetLocal EnableExtensions DisableDelayedExpansion
if "%$current%" NEQ "%$changed%" (
If EXIST "%$changed%" (
Set "$changed=%$changed%~"
Call %0
Goto :EOF
)
Echo Renaming "%$current%" to "%$changed%".
%$RENAME% "%$current%" "%$changed%"
Set "$current=%$changed%"
)
Goto :EOF

Frank P. Westlake

unread,
Dec 19, 2011, 1:29:04 PM12/19/11
to
I inadvertently left it the way I last used it. Comment out the second
of the following two SET statements for a test run only.

> :: For demo:
> Set "$RENAME=Echo Rename"
> :: For real:
> Set "$RENAME=Rename"

Frank

Dr J R Stockton

unread,
Dec 19, 2011, 6:44:04 PM12/19/11
to
In alt.msdos.batch.nt message <4EEDB16...@uwasa.fi>, Sun, 18 Dec
2011 11:24:51, Timo Salmi <t...@uwasa.fi> posted:

>How to list folders which have files (or immediate subfolders) with % !
>& or ^ in the names?

I offer

prompt>SEEK . s @+[#x21#x25] q100000
2011-12-19 19:03:44 4 .....a.. "aaa!bbbb"
2011-12-19 19:04:01 4 .....a.. "my-dummy\ccccc%dd"
prompt>

and, if only the names are wanted, add the word o to the end of the
command line. The ability to use #xhh and #uhhhh in any argument past
the first saves all worry about escape characters (in that location, \
can be used, as @+ (& @- which would show the non-matches) are followed
by a JScript Regular Expression).

A single substring, such as ! or %, could be found with the h option
instead of the @ argument.

SEEK invokes SEEK.BAT which calls SEAKFYLE.JS for execution by WSH. See
<http://www.merlyn.demon.co.uk/programs/32-bit/seakfyle.htm>.

For those who prefer it, the dates can be in ordinal (yyyy-ddd) or Week-
numbering (yyyy-Www-d) form, or as time_t in milliseconds.

The displayed name (the RegExp searches the whole line, but those
characters cannot occur elsewhere in it) can be the full name (e.g.
C:\....."), the name from the current directory, or just the file name
(Options c0 c1 c2).

The above Option s does all subfolders, but it would not be difficult to
add an integer for depth limit, if thought useful [1].

Caution - if the first argument is a reference to the root directory,
things get VERY slow in parts. I presume getFolder always gets the
entire tree.

Warning - this is a new script, a 32-bit substitute for HUNT, and may
change frequently.

Ideal for amusing any programmer snowbound over Christmas - about 350
lines, some blank.

[1] P.S. Done, but not yet uploaded.

--
(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.

Timo Salmi

unread,
Dec 21, 2011, 4:33:25 AM12/21/11
to
On 18.12.2011 15:47 Timo Salmi wrote:
> I sense a new FAQ item to the collection in the making.

186} How to list folders which have files with % ! & or ^ in the names?
http://www.netikka.net/tsneti/info/tscmd186.php
0 new messages