检查输入是文件还是文件夹 [英] Check if input is a file or folder

查看:74
本文介绍了检查输入是文件还是文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的命令:

set /p txtfile=Write destination to the .txt file:

现在我需要知道文件是否确实存在:

now i need to know if the file really exists so:

if exist %txtfile% echo file found.

它可以工作,但是如果用户给我写了C:\,它将显示找到文件".我想知道是否可以使用批处理来了解文件扩展名,有什么想法吗?

it works, but if the user writes me C:\ it will display "file found" to. I want to know is there a way to know a file extension using batch, any ideas?

推荐答案

您可以使用TYPE将其标识为文件.但是,如果文件很大,可能不是最好的方法.

You can identify it as a file using TYPE. However, it might not be the best way if it is a large file.

SET "DIR_ITEM=C:\Windows"

TYPE "%DIR_ITEM%" 1>NUL 2>&1
IF ERRORLEVEL 1 (
    ECHO "%DIR_ITEM%" is not a file
) ELSE (
    ECHO "%DIR_ITEM% is a file
)

这篇关于检查输入是文件还是文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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