Only showing three letter extensions with dir

  • Thread starter Thread starter Csaba Gabor
  • Start date Start date
C

Csaba Gabor

My editor (emacs) likes to make backups by placing a tilde (~) on the
end of the filename. If I then do a directory of that particular
filetype by means of:

dir *.typ

then I get a list like
file1.typ
file1.typ~
file2.typ
file2.typ~
....

Is there a way (especially using dir only (without piping)) to get only
the *.typ without the ~ at the end?

Thanks,
Csaba Gabor from New York
 
My editor (emacs) likes to make backups by placing a tilde (~) on the
end of the filename. If I then do a directory of that particular
filetype by means of:

dir *.typ

then I get a list like
file1.typ
file1.typ~
file2.typ
file2.typ~
...

Is there a way (especially using dir only (without piping)) to get only
the *.typ without the ~ at the end?

AFAIK that's not easily done with the DIR command in
CMD.EXE/COMMAND.COM. The only way I can imagine would be indeed to pipe
DIR's output into FIND or FINDSTR, or a FOR loop which inspects the file
extension.

4NT can do it like this:
DIR /[!*.typ~]
The parameter /[!] specifies an exclusion range; see
<http://jpsoft.com/help/filexranges.htm>.

Alternatively, 4NT can be directed not to match short filenames with the
directive:
OPTION //Win32SFNSearch=No
and the command
DIR *.typ
will the show only those files. See
<http://jpsoft.com/help/lfnsearch.htm>.

I believe there is a similar directive for the free 4DOS
(Win95SFNSearch), but I doubt this would work under any NT-class OS; 4NT
is a commercial product.
 
You might try something like the following:

for /f "tokens=*" %I in ('dir /b *.typ') do @if %~xI==.typ echo %I

This outputs:

file1.typ
file2.typ


If you want to list all four files, then try this:

for /f "tokens=*" %I in ('dir /b *.typ') do @if %~xI==.typ (echo %I) else
(echo %~nI.typ)

You will get the following:

file1.typ
file1.typ
file2.typ
file2.typ




Hope this helps,

-Tyler


--
____________________________________________________
This information is provided "AS IS" with no warranties and confers no
rights.


| My editor (emacs) likes to make backups by placing a tilde (~) on the
| end of the filename. If I then do a directory of that particular
| filetype by means of:
|
| dir *.typ
|
| then I get a list like
| file1.typ
| file1.typ~
| file2.typ
| file2.typ~
| ...
|
| Is there a way (especially using dir only (without piping)) to get only
| the *.typ without the ~ at the end?
|
| Thanks,
| Csaba Gabor from New York
|
 
The fact that "dir *.typ" also displays *.typ* is caused by the behaviour
how the file system creates short file names.
If you don't want the files *.typ* to be displayd you can change this in the
registry:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"Win95TruncatedExtensions"=dword:00000000

But this works only for files that are created after the change in the
registry was made.
If you want to do the changes for all old files you have to copy all files
od a certain drive to a different drive, delete the original files and copy
them back again.

Konrad Kullig
 
Back
Top