测试批处理文件中的文件属性 [英] Testing for file attribute in batch file
本文介绍了测试批处理文件中的文件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在写一个批处理文件,我需要知道文件是否是只读的.我该怎么办?
I'm writing a batch file and I need to know if a file is read only. How can I do that ?
我知道如何使用%〜a修饰符来获取它们,但是我不知道如何处理此输出.它给出类似-ra ------的信息.如何在批处理文件中对此进行解析?
I know how to get them using the %~a modifier but I don't know what to do with this output. It gives something like -ra------. How can I parse this in batch file ?
推荐答案
类似的方法应该起作用:
Something like this should work:
@echo OFF
SETLOCAL enableextensions enabledelayedexpansion
set INPUT=test*
for %%F in (%INPUT%) do (
set ATTRIBS=%%~aF
set CURR_FILE=%%~nxF
set READ_ATTRIB=!ATTRIBS:~1,1!
@echo File: !CURR_FILE!
@echo Attributes: !ATTRIBS!
@echo Read attribute set to: !READ_ATTRIB!
if !READ_ATTRIB!==- (
@echo !CURR_FILE! is read-write
) else (
@echo !CURR_FILE! is read only
)
@echo.
)
运行此命令时,将得到以下输出:
When I run this I get the following output:
File: test.bat
Attributes: --a------
Read attribute set to: -
test.bat is read-write
File: test.sql
Attributes: -ra------
Read attribute set to: r
test.sql is read only
File: test.vbs
Attributes: --a------
Read attribute set to: -
test.vbs is read-write
File: teststring.txt
Attributes: --a------
Read attribute set to: -
teststring.txt is read-write
这篇关于测试批处理文件中的文件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文