如何检查文件夹是否存在?使用批处理脚本?

时间:2017-05-29 15:45:18

标签: batch-file

如果用户没有读取权限,如何检查文件夹是否存在?

我正在编写一个脚本来自动为用户映射驱动器。用户具有对其文件夹的读取权限,但不具有对父文件夹的读取权限。因此,即使文件夹存在,我当前的Generated Schema cannot use Interface or Union types for execution也会直接转到if statement

我目前的代码如下所示

else

因此,用户对其文件夹名称具有读取权限,结构为if exist "\\domain\parent\%drive%" ( net use i: /delete net use i: \\domain\parent\%drive% /P:YES ) else if exist "\\domain\parent\%username%" ( net use i: /delete net use i: \\domain\parent\%username% /P:YES ) else ( echo error: folder not found echo error: unable to map I drive pause exit ) %drive%,但他们对%username%文件夹没有读取权限。

我可以手动映射驱动器,但我想知道是否可以使用parent检查文件夹是否存在,即使用户没有{{{的读取权限也是如此1}}?

更新:如果用户对父文件夹和子文件夹具有读取权限,但是有一些方法可以检查文件是否存在,即使用户没有对父文件夹的读取权限,也可以使用此代码吗?

1 个答案:

答案 0 :(得分:0)

这可以帮到你:

setlocal enableDelayedExpansion

for /f "delims=" %p in ('attrib ntuser.ini') do (
    set process=!%p:~0,8!
    echo !process! | findstr "H"
)

此命令执行:

  • 读取file.ext
  • 的属性
  • 查看权限结果是否包含H,如果是,则表示文件 H idden,您可以将H更改为您喜欢的任何内容,只需检查{ {1}}

这是正确的attrib /?声明。

if

您应该组合多个if语句来模拟if exist filename/foldername ( command ) else ( if blah == blah ( command2 ) else ( command3 ) ) 语句

相关问题