下面的代码是运行一个文件夹,其中包含几个文件(结尾为“* _perms.txt”),根据该用户名定义目录的权限。理想情况下,代码会在某些时候删除目录和扩展名,只需使用.txt文件的名称作为用户。
现在代码通过迭代文件来工作;询问权限用户名是什么;其次是许可级别;然后遍历文件中列出的目录设置权限。
除非没有。
当我运行文件并输入用户和级别时,它似乎不会确认输入的内容,而是使用上次运行中的最后输入值(适用于所有)。
我是一个完整的n00b批处理,请原谅任何未完成的编码错误或做法。此外,对代码的任何其他建议将非常感激。
:: Get the files which define the permissions
FOR /R %perms% %%i IN ("*_perms.txt") DO (
echo %%i
:: TO-DO - remove path and file extension
echo ++++ %%i Folder ++++ >> %logFile% & echo.
SET /P permUser=:Enter the user.
SET /P permType=:Enter the user access right.
:: Set the permissions for the folders specified
FOR /F %%j IN (%%i) DO (
::echo %%j
::echo %permUser%
echo %VSS_home%\%%j
:: N.B - uses the last entered parameter on the command-line.
:: also does not get recorded onto log file.
net share permDir=%VSS_home%\%%j /grant:%permUser%,%permType% /users:%MaxUsers% /remark:%%j >> %logFile%
echo User: %permUser%, Rights: %permType% >> %logFile%
)
)
答案 0 :(得分:1)
首先,请参阅this discussion,了解如何在括号内使用::
标签注释。基本上,不要使用它们,请使用rem
!
第二次,请参阅Delayed Expansion了解如何在括号内设置变量。基本上,如果要访问在括号内设置的变量,则需要setlocal EnableDelayedExpansion
。
以下是一些很好的帖子,解释了如何处理批处理文件。
https://stackoverflow.com/a/7970912/891976
https://stackoverflow.com/a/4095133/891976
重要批次参考