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

How to test if a directory contains any files with long names? Revisited

24 views
Skip to first unread message

Timo Salmi

unread,
Apr 18, 2005, 1:37:15 AM4/18/05
to
I had not been able to get this quite right for MS-DOS contrary to
85} How to test if a folder contains any files with long names?
for plain XP script in ftp://garbo.uwasa.fi/pc/link/tscmd.zip

Here is another attempt. There are more concise solutions (see the
reference at the end) but this one also demonstrates 4DOS-aided
command.com batches discussed recently. Using the straight command.com
conventions.

DRAFT

This one is for Windows 95. Not tested for any other Windows versions.
4DOS is utilized.

@echo off
::
:: Utilize 4DOS
set fourpath=L:\4DOSHOME
set path_=%path%
set path=l:\4doshome;%path%
if exist %fourpath%\4dos.com goto _setemp
echo Exiting: 4DOS.COM is not available
goto _clean
::
:: Customize temp location, not necessary but good for debugging
:_setemp
set temp_=%temp%
if not [%mytemp%]==[] set temp_=%mytemp%
::
:: Which directory is investigated
set dir_=%1
if [%1]==[] set dir_=.
::
:: Use 4DOS for the long and short name directory listings
4dos /e:4096 /c dir /b /l "%dir_%">%temp_%\tmp$$$b.dir
4dos /e:4096 /c dir /b /l /x "%dir_%">%temp_%\tmp$$$x.dir
::
:: See if the two directory listings differ
fc %temp_%\tmp$$$b.dir %temp_%\tmp$$$x.dir|find /i "FC: no
differences encountered">nul
if errorlevel==1 set lfn_=true
if [%lfn_%]==[] echo No long file names found in directory %1
if not [%lfn_%]==[] echo Long file names found in directory %1
::
:_cleanup
set path=%path_%
for %%f in (%temp_%\tmp$$$*.dir) do if exist %%f del %%f
for %%v in (temp_ lfn_ path_ fourpath) do set %%v=

References/Comments:
http://www.google.com/groups?selm=d07p7u$ve7$01$3...@news.t-online.com

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html

William Allen

unread,
Apr 18, 2005, 2:48:34 AM4/18/05
to
"Timo Salmi" wrote in message

> I had not been able to get this quite right for MS-DOS contrary to
> 85} How to test if a folder contains any files with long names?
> for plain XP script in ftp://garbo.uwasa.fi/pc/link/tscmd.zip
>
> Here is another attempt. There are more concise solutions (see the
> reference at the end) but this one also demonstrates 4DOS-aided
> command.com batches discussed recently. Using the straight command.com
> conventions.
>
> DRAFT
>
> This one is for Windows 95. Not tested for any other Windows versions.
> 4DOS is utilized.
>
> @echo off
> ::
> :: Utilize 4DOS
> set fourpath=L:\4DOSHOME
> set path_=%path%
> set path=l:\4doshome;%path%

For the set path line above, I think you probably meant to write:
set path=%fourpath%;%path%
so that user alteration of SET FOURPATH ramifies through the file.

...snip


> :: Use 4DOS for the long and short name directory listings
> 4dos /e:4096 /c dir /b /l "%dir_%">%temp_%\tmp$$$b.dir
> 4dos /e:4096 /c dir /b /l /x "%dir_%">%temp_%\tmp$$$x.dir

If the folder concerned happens to contain no files, result is
correct, but note that 4Dos DIR /b (unlike MS-DOS DIR /b) reports
a "file not found" error message. Some report that there are no
files in the folder may be useful, but as it stands, user receives
two reports.

============Screen capture Windows 95
C:\WORK>md test

C:\WORK>timodemo.bat c:\work\test
File not found "c:\work\test\*"
File not found "c:\work\test\*"
No long file names found in directory c:\work\test
C:\WORK>
============End screen capture

...snip


> for %%v in (temp_ lfn_ path_ fourpath) do set %%v=

Need to clear the dir_ variable, too.

Posted file is a useful example for new 4Dos users to show how
to begin to add a few 4Dos commands to their existing batch files
and make an easy start to learning the new syntax.

--
William Allen


Timo Salmi

unread,
Apr 18, 2005, 7:59:45 AM4/18/05
to
William Allen wrote:
> "Timo Salmi" wrote in message
>>DRAFT

>> set fourpath=L:\4DOSHOME
>> set path=l:\4doshome;%path%

> For the set path line above, I think you probably meant to write:
> set path=%fourpath%;%path%

This is exactly why it is useful to subject one's drafts to public
scrutiny. One gets welcome observations about such hiccups. Thank you.

>> 4dos /e:4096 /c dir /b /l "%dir_%">%temp_%\tmp$$$b.dir
>> 4dos /e:4096 /c dir /b /l /x "%dir_%">%temp_%\tmp$$$x.dir

> If the folder concerned happens to contain no files, result is
> correct, but note that 4Dos DIR /b (unlike MS-DOS DIR /b) reports
> a "file not found" error message. Some report that there are no
> files in the folder may be useful, but as it stands, user receives
> two reports.

Right. But maybe already such production level fine tuning, that I'll
leave it up to the potential user.

> Need to clear the dir_ variable, too.

As per the first comment.

> Posted file is a useful example for new 4Dos users to show how
> to begin to add a few 4Dos commands to their existing batch files
> and make an easy start to learning the new syntax.

Being on the learning curve oneself often is an advantage in writing
FAQs. Most of all I wanted to understand how one can utilize 4DOS
without having to commit to major system decisions in the traditional
setting. That, I think, I got.

billious

unread,
Apr 18, 2005, 9:21:38 AM4/18/05
to

"Timo Salmi" <t...@uwasa.fi> wrote in message
news:4263478d$1...@news.dnainternet.net...

>I had not been able to get this quite right for MS-DOS contrary to
> 85} How to test if a folder contains any files with long names?
> for plain XP script in ftp://garbo.uwasa.fi/pc/link/tscmd.zip
>
> Here is another attempt. There are more concise solutions (see the
> reference at the end) but this one also demonstrates 4DOS-aided
> command.com batches discussed recently. Using the straight command.com
> conventions.
>
[4DOS solution snipped to make whingers happier]

I'm not really sure whether your object is to produce a 4DOS solution for 9x
or to improve on your XP solution, Timo.

Leaving aside the twin arguments about 4DOS not being part of MSDOS and
XP-only solutions belonging in alt.msdos.batch.nt, I'll put in my two bob's
worth here, since it's the only current thread on the matter...

Your XP solution appears to use a FIND /V "(" to exclude the final 2 lines
of a straight DIR listing, since the last line inconveniently contains 5
tokens.

Unfortunately, it also zaps possibly-long filenames that contain "(" as a
side-effect.

Here's my XP solution - with line numbers for ease of discussion, and noting
that I customarily use Yxx for tem-envvar names (where xx may be LF for Long
Filename or TF for Temporary Filename) because a straight SET then shows my
tempvars conveniently at the end of the list.

I should also mention that I use XPHSP2 with all the latest patches from
Bill's Backyard Software Company - configured with default settings except
for date and country localisation (DD/MM/CCYY and Australia.) This means I
run in EXTENSIONS-ENABLED mode by default (both relevant registry settings =
1 AND CMD/E:ON for good measure)

[01]@echo off
[02]set ylf=N
[03]:: establish unique tempfilename-prefix
[04]set ytf=L
[05]:tloop
[06]set ytf=%ytf%f
[07]if exist %temp%\%ytf%* goto tloop
[08]set ytf=%temp%\%ytf%
[09]pushd .
[10]for /f "tokens=*" %%a in ("%~1") do cd "%%a"
[11]dir /b/a-d 2>nul|find /v "" >nul 2>nul
[12]if errorlevel 1 goto cleanup
[13]for /f "tokens=*" %%a in ('dir /b /a-d ') do echo %%~nxa >>%ytf%.1 2>nul
[14]for /f "tokens=*" %%a in ('dir /b /a-d ') do echo %%~snxa >>%ytf%.2
2>nul
[15]fc %ytf%.1 %ytf%.2 >nul
[16]if errorlevel 1 set ylf=Y
[17]del %ytf%*
[18]:cleanup
[19]popd
[20]set ytf=


Lines 4..8 simply establish a file-prefix for tempfiles

Line 9 is interesting. I found (and have commented in another thread) that
the argument "." is necessary - but it isn't according to the documentation
(and sense)

On my system, PUSHD/...CD wherever .../POPD would leave the current
directory as the last directory visited - POPD did not appear to restore the
original directory. Changing the PUSHD to "PUSHD ." fixed the problem.

Line 10 : I found that it was necessary to actually change to the target
directory, otherwise the ~snx (line 14) did not work - it appears to work
ONLY for the current directory.

Line 11/12 -test for empty directory...

Line 13/14 two separate report files - one with the long and the other with
the short name.

Line 15 : FC happily sets errorlevel appropriately - and
language-independently...

rest is obvious; YLF set to Y or N.

HTH

Bill

Message has been deleted

Timo Salmi

unread,
Apr 18, 2005, 10:15:51 AM4/18/05
to William Allen
William Allen wrote:
> "Timo Salmi" wrote in message
>>FAQs. Most of all I wanted to understand how one can utilize 4DOS
>>without having to commit to major system decisions in the traditional
>>setting. That, I think, I got.

> With your permission, we think it would be useful to put a link to
> your material in our 4Dos Guide textfile. If you agree, and when you
> are ready, let us know your preference for what page or data file URL
> we should write a link to (I realise that the 4Dos examples may be
> only a small proportion of the total examples).

It will not be a separate entity, but within the (familiar)
250909 Oct 12 2004 ftp://garbo.uwasa.fi/pc/link/tsbat.zip
tsbat.zip Useful MS-DOS batch files and tricks, T.Salmi
when the next version comes out. Pointing to common package locations
does not require explicit permissions, so it is a given.

Timo Salmi

unread,
Apr 18, 2005, 10:31:31 AM4/18/05
to
billious wrote:
> "Timo Salmi" <t...@uwasa.fi> wrote in message
>>I had not been able to get this quite right for MS-DOS contrary to
>>85} How to test if a folder contains any files with long names?
>>for plain XP script in ftp://garbo.uwasa.fi/pc/link/tscmd.zip

> [4DOS solution snipped to make whingers happier]

> I'm not really sure whether your object is to produce a 4DOS solution for 9x
> or to improve on your XP solution, Timo.

The former, but I also took a note of your useful feedback to for the
latter.

> Leaving aside the twin arguments about 4DOS not being part of MSDOS and

In principle the situation in using 4DOS as a third party enhancement is
no different from using other programs to enhance MS-DOS batches. There
are many, including gawk, sed, hunt, customized binaries, QBASIC,
XXCOPY, XSET, WSH, and so on. They have been utilized extensively in
here.

> Your XP solution appears to use a FIND /V "(" to exclude the final 2 lines

FIND and the trick used being also a part of any of the platforms, the
specter of what goes in where does not have to arise.

> of a straight DIR listing, since the last line inconveniently contains 5
> tokens.
> Unfortunately, it also zaps possibly-long filenames that contain "(" as a
> side-effect.

Replacing with FIND /V "(s) " will considerably diminish the
probability. Thanks for the thumbs up.

Timo Salmi

unread,
Apr 18, 2005, 3:07:34 PM4/18/05
to
billious wrote:
> "Timo Salmi" <t...@uwasa.fi> wrote in message

>>85} How to test if a folder contains any files with long names?

> XP-only solutions belonging in alt.msdos.batch.nt, I'll put in my two bob's

> worth here, since it's the only current thread on the matter...

I'll take the liberty of redirecting to news:alt.msdos.batch.nt to avoid
the groups range issue altogether, whatever particular view one might
happen to hold.

> Your XP solution appears to use a FIND /V "(" to exclude the final 2 lines
> of a straight DIR listing, since the last line inconveniently contains 5
> tokens.
> Unfortunately, it also zaps possibly-long filenames that contain "(" as a
> side-effect.

How about this revision?

@echo off & setlocal enableextensions enabledelayedexpansion
set lfn_=
for /f "skip=4 tokens=* delims=" %%a in (
'dir /x /a:-d /-c "%~1" ^|findstr /v /b /c:" "') do (
set line_=%%a
set sfn_=!line_:~36,12!
if not "!sfn_!"==" " set lfn_=true)
if [%lfn_%]==[] (
echo No long file names found in folder %1
) ELSE (
echo Long file names found in folder %1)
endlocal & goto :EOF

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland

Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip

Klaus Meinhard

unread,
Apr 18, 2005, 1:59:34 AM4/18/05
to
Timo Salmi wrote:

> 85} How to test if a folder contains any files with long names?

> References/Comments:
> http://www.google.com/groups?selm=d07p7u$ve7$01$3...@news.t-online.com

Just a thought: depending on the task at hand even the test per se might
be dispensable. To make sure only short file names are used one can use
the %@sfn function in the relevant places.


--
* Klaus Meinhard *
www.4dos.info
- 4DOS Info -
- Info for DOS -


Dr John Stockton

unread,
Apr 19, 2005, 6:45:51 AM4/19/05
to
JRS: In article <4263478d$1...@news.dnainternet.net>, dated Mon, 18 Apr
2005 08:37:15, seen in news:alt.msdos.batch, Timo Salmi <t...@uwasa.fi>
posted :

>I had not been able to get this quite right for MS-DOS contrary to
>85} How to test if a folder contains any files with long names?
>for plain XP script in ftp://garbo.uwasa.fi/pc/link/tscmd.zip

I believe I have a superior approach : except for test purposes, I
simply avoid giving files names not acceptable to MSDOS proper. Granted
that I don't always remember to use upper-case letters, but that is of
minor significance.

Suggestion for BATFAQ, for the more advanced users with Win95..ME :
###) How do I change the letters of my file names to all upper-case.
(caveat : letters A-Z only). ISTR that the answer has been given here
in the past, but not what it was.


>Here is another attempt. There are more concise solutions (see the
>reference at the end) but this one also demonstrates 4DOS-aided
>command.com batches discussed recently. Using the straight command.com
>conventions.

Would it not be well to put such material in the 4DOS newsgroup
news:comp.os.msdos.4dos? It was, after all, I presume, formed for that
purpose by a proper Big-8 vote or whatever else might at the time have
been the procedure; and it needs more traffic if it is to give the
impression that 4DOS is worth having.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; Win98. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.

Timo Salmi

unread,
Apr 19, 2005, 3:14:51 PM4/19/05
to
Dr John Stockton <sp...@merlyn.demon.co.uk> wrote:
> I believe I have a superior approach : except for test purposes, I
> simply avoid giving files names not acceptable to MSDOS proper. Granted

I can't afford that approach, since I do not always handle only my
own files. Some of the names I port are decided in the workplace by
my colleagues and so onwith different interests. In other words my
system are not completely stand-alone even if they are solely mine.

> Suggestion for BATFAQ, for the more advanced users with Win95..ME :
> ###) How do I change the letters of my file names to all upper-case.

It is a good suggestion. But my FAQ still is mostly MS-DOS vanilla,
with an occasional excursion. Anyway a potential starting point
would be the FAQ's item
7) How can I convert a lowercase parameter to uppercase?

> >Here is another attempt. There are more concise solutions (see the
> >reference at the end) but this one also demonstrates 4DOS-aided
> >command.com batches discussed recently. Using the straight command.com
> >conventions.

In case anyone missed. This was as much about command.com batch
programming as 4DOS. The "this" being
164) How do I write 4DOS-aided batch files under COMMAND.COM?
165) How to test if a directory contains any files with long names?

> Would it not be well to put such material in the 4DOS newsgroup
> news:comp.os.msdos.4dos?

I'll quite soon release the said TSBAT update and crosspost the
announcement.

> It was, after all, I presume, formed for that
> purpose by a proper Big-8 vote or whatever else might at the time have
> been the procedure; and it needs more traffic if it is to give the
> impression that 4DOS is worth having.

There is the added advantage that a comp newsgroup AFAIK propagates
much better than an alt newsgroup. Involving news:comp.os.msdos.4dos
would thus to the advantage of all concerned. However, I am now
practically done with the involved items which I set out to write.
Thus it is too late in the process in a sense.

But in case anyone in news:comp.os.msdos.4dos who is not reading
news:alt.msdos.batch is interested, here is my original anchor
http://www.google.com/groups?selm=4263478d$1...@news.dnainternet.net
to start from.

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland

Useful batch files and tricks ftp://garbo.uwasa.fi/pc/link/tsbat.zip

William Allen

unread,
Apr 19, 2005, 6:09:03 PM4/19/05
to
"Dr John Stockton" wrote in message
...snip

> Suggestion for BATFAQ, for the more advanced users with Win95..ME :
> ###) How do I change the letters of my file names to all upper-case.
> (caveat : letters A-Z only). ISTR that the answer has been given here
> in the past, but not what it was.

The following technique originally posted by Tom Lavedas:

Lines that don't begin with two spaces have wrapped accidentally
====Begin cut-and-paste (omit this line)
@ECHO OFF
for %%v in (/%1) do set Ucase=%%v
for %%"/" in ("set Ucase=") do %%%Ucase%
ECHO %Ucase%
====End cut-and-paste (omit this line)
For Win95/98/ME study/demo use. Cut-and-paste as plain-text Batch file.
Batch file troubleshooting: http://www.allenware.com/find?UsualSuspects

Assumes no [Space]s in passed parameter:

============Screen capture Windows 95
C:\WORK>ucase CelesteMannaparisLuxCecisDuxIgnarisSolamenAngelorum
CELESTEMANNAPARISLUXCECISDUXIGNARISSOLAMENANGELORUM


C:\WORK>
============End screen capture

Modification suggested by Laura Fairhead in same thread, which
can be used to handle strings containing [Space]s:

Lines that don't begin with two spaces have wrapped accidentally
====Begin cut-and-paste (omit this line)
@ECHO OFF
SET UC=Look after Mr Bond. See that some harm comes to him.
ECHO.%UC%
PATH "SET UC=%UC%|PATH %PATH%"
%PATH%
ECHO.%UC%

====End cut-and-paste (omit this line)
For Win95/98/ME study/demo use. Cut-and-paste as plain-text Batch file.
Batch file troubleshooting: http://www.allenware.com/find?UsualSuspects

============Screen capture Windows 95
C:\WORK>ucase2
Look after Mr Bond. See that some harm comes to him.
LOOK AFTER MR BOND. SEE THAT SOME HARM COMES TO HIM.


C:\WORK>
============End screen capture

--
William Allen
Free interactive Batch Course http://www.allenware.com/icsw/icswidx.htm
Batch Reference with examples http://www.allenware.com/icsw/icswref.htm
Header email is rarely checked. Contact us at http://www.allenware.com/


Timo Salmi

unread,
Apr 20, 2005, 1:49:53 PM4/20/05
to
Dr John Stockton wrote:
> Suggestion for BATFAQ, for the more advanced users with Win95..ME :
> ###) How do I change the letters of my file names to all upper-case.
> (caveat : letters A-Z only). ISTR that the answer has been given here
> in the past, but not what it was.

DRAFT (includes ÅÄÖ, easily dropped)

166. How do I uppercase all the filenames in a directory?

Be careful. The long names are both upper cased, and made short if
wildcards are utilized. Experiment first sufficiently with
non-essential material! SED.EXE is needed in this batch.
@echo off
if [%1]==[] goto _usage
for %%f in (%1) do if ["%%f"]==[%1] goto _nowilds
echo Parameter %1 contains wildcards or is not eclosed in quotes ""
goto _out1
::
:_nowilds
echo %1|sed
"y/abcdefghijklmnopqrstuvwxyzåäö/ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ/"|sed
"s/.*/@set uc_=&/">%temp%\tmp$$$.bat
for %%c in (call del) do %%c %temp%\tmp$$$.bat
if not exist %uc_% goto _nofind
ren %uc_% %uc_%
dir %uc_%|find /i %uc_%
goto _out1
::
:_nofind
echo File %1 not found
goto _out1
::
:_usage
echo.
echo Usage: %0 "filename" No wildcards!
echo.
echo For wildcards use e.g. FOR %%f IN (*.txt) DO CALL %0 "%%f"
echo Warning: Using wildcards will produce SHORT (8+3) filenames!
echo.
echo Experiment first extensively with non-essential files
echo.
goto _out1
::
:_out1
for %%v in (uc_) do set %%v=

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland

Timo Salmi

unread,
Apr 20, 2005, 11:48:24 PM4/20/05
to
Timo Salmi wrote:
> Dr John Stockton wrote:
>> Suggestion for BATFAQ, for the more advanced users with
Win95..ME :
>> ###) How do I change the letters of my file names to all upper-case.

I am crossposting this version to news:comp.os.msdos.4dos and
resetting the followups to it.

I am exceptionally including the entire old solution for comparison
for the comp.os.msdos.4dos readers. I am postquoting the solution
since in this kind of a case it is for once genuinely warranted.

The difference in the complication level between the two solutions
is dramatic, in favor of 4DOS.

DRAFT for tsbat:

The FAQ items #164 and #165 demonstrated how to write 4DOS-aided
COMMAND.COM batches. For comparison below is the solution for the
task at hand run in an actual 4DOS.COM window:
@echo off
rem UPCASE4.BTM Coverts the file names in the default directory
to upper case
rem File names with spaces in them are supported
rem No forced conversion to short file names
::
for %%f in (*.*) do (
ren /p "%%f" "%@UPPER[%%f]"
)
dir /b /f /p /a:-d

0 new messages