为什么Windows命令DIR在搜索* .tif文件时也会输出* .tiff文件? [英] Why are also *.tiff files output by Windows command DIR on searching for *.tif files?

查看:32
本文介绍了为什么Windows命令DIR在搜索* .tif文件时也会输出* .tiff文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Windows命令 DIR 来仅查找 TIF 文件,即扩展名为 .tif 的文件.因此,我使用以下小批处理文件:

I want to use the Windows command DIR in order to find only TIF files, i.e. files with extension .tif. Therefore I use the following small batch file:

for /f "delims=" %%a IN ('dir /b /a-d /s "C:\wolter\testversion-input\*.tif"') do echo %%a

for /f "delims=" %%a IN ('dir /b /a-d /s "R:\wolter\testversion-input\*.tif"') do echo %%a

现在,我想知道此命令还能找到 TIFF 文件,即扩展名为 .tiff 的文件.

Now I am wondering that this command also finds TIFF files, i.e. files with extension .tiff.

因此,我进行了一些测试,发现命令 DIR 在我的计算机上找到了 TIF AND TIFF 文件使用存储的 TIF TIFF 文件在文件夹 C:\ wolter \ testversion-input \ 中驱动 C:,但是在我的驱动器 R:中的文件夹 R:\ wolter \ testversion-input \ 中只能通过命令 DIR 找到 TIF 文件,尽管此文件夹还包含 TIF TIFF 文件.

So I made some tests and found out that the command DIR finds TIF AND TIFF files on my drive C: in folder C:\wolter\testversion-input\ with stored TIF and TIFF files, but on my drive R: in folder R:\wolter\testversion-input\ are found by the command DIR only TIF files although this folder contains also TIF and TIFF files.

我的目标是仅查找 TIF 文件.

My goal is to find only TIF files.

如何仅查找和处理扩展名为 .tif 的文件,而排除扩展名为 .tiff 的文件?

How to find and process only files with file extension .tif with excluding files with file extension .tiff?

推荐答案

默认情况下,扩展名将根据其8.3兼容文件名进行匹配.您可以禁用8.3命名(将文件名限制为八个字符,可选扩展名限制为三个字符).

The extensions are being matched, by default, according to their 8.3 compliant file names. You could disable 8.3 naming, (which restricts file names to eight characters and optional extensions to three characters).

要对您的NTFS分区执行此操作,请打开命令提示符"窗口以管理员身份运行",然后输入:

To do that for your NTFS partition, open a Command Prompt window 'Run as administrator', and enter:

"%__AppDir__%fsutil.exe" behavior set disable8dot3 1

请注意,禁用8.3命名通常可以提高目录枚举性能,尤其是在同一目录中存在大量相似名称的文件的情况下.但是,某些应用程序可能无法找到使用长文件名LFN的文件和目录.禁用也不会删除已经创建的SFN.

Please note that disabling 8.3 naming, may generally improve directory enumeration performance especially in situations where large numbers of similarly named files exist in the same directory. However some applications may not be able to locate files and directories which use long file names, LFN's. Also disabling does not delete the already created SFN's.

对于替代方法,您有一些选择.

For alternatives, you have a few options.

  1. 使用结果的元变量扩展来检查匹配的扩展(最慢):

For /F "Delims=" %%G In ('Dir /A-D /B /S "R:\wolter\testversion-input\*.tif"') Do If "%%~xG" == ".tif" Echo %%G

  • 将结果从 Dir 通过 findstr.exe 传递,以仅过滤以不区分大小写的字符串 .tif 结尾的内容:

  • Pass the results from Dir through findstr.exe to filter only those which end with the case insensitive string .tif:

    For /F "Delims=" %%G In ('Dir /A-D /B /S "R:\wolter\testversion-input\*.tif" ^| "%__AppDir__%findstr.exe" /EIL ".tif"') Do Echo %%G
    

  • 使用将与确切扩展名匹配的 where.exe :

    For /F "Delims=" %%G In ('""%__AppDir__%where.exe" /R "R:\wolter\testversion-input" "*.tif" 2> NUL"') Do Echo %%G
    

    但是, where.exe 也与%PATHEXT%下列出的扩展名匹配,这意味着尽管它可能会省略您的 .tiff 文件,它可能会返回扩展名,例如 .tif.com .tif.exe .tif.bat .tif.cmd .tif.vbs .tif.vbe .tif.js .tif.jse .tif.wsf .tif.wsh .tif.msc .因此,为了增强鲁棒性,您应该暂时取消定义该变量:

    However, where.exe, also matches against extensions listed under %PATHEXT%, this means that whilst it may omit your .tiff files, it could feasibly return extensions like .tif.com, .tif.exe, .tif.bat, .tif.cmd, .tif.vbs, .tif.vbe, .tif.js, .tif.jse, .tif.wsf, .tif.wsh, and .tif.msc too. You should therefore, for extra robustness, temporarily undefine that variable:

    For /F "Delims=" %%G In ('"(Set PATHEXT=) & "%__AppDir__%where.exe" /R "R:\wolter\testversion-input" "*.tif" 2> NUL"') Do Echo %%G
    

  • 这篇关于为什么Windows命令DIR在搜索* .tif文件时也会输出* .tiff文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆