我正在努力实现以下目标:
对于源文件夹%1
中的每个文件;显示它的详细信息,询问用户是否应该复制文件,如果用户回答“否”则显示“跳过”消息,否则将文件复制到目标文件夹%2
,将副本的权限设置为“读取”只有“,并显示一条消息。
这是我迄今为止所管理的内容,但最后一部分我没有理解。
@echo off
rem if the source folder does not exist, display a message and exit
if exist "%1%" (
echo .
) else (
echo Source folder doesn't exist.
exit /b
)
if exist "%2%" (
echo Directory exists
) else (
md %2
echo Directory Created
)
FOR /F "DELIMS==" %%f in ('DIR "%1" /B') DO (
ECHO %%f
set p = NULL
SET /p p="Copy(y/n)?"
IF "%p%" == "y" (
COPY "%1\%%f" "%2"
ECHO Copied %%f to %2
) ELSE (
ECHO "%%f" Skipped
)
)
这可能吗?如果它可以通过迭代过程的子程序(复制和设置权限)来完成吗?
答案 0 :(得分:1)
我制作了一个批处理脚本来执行此操作
@echo off
::This batch file works with arguments or no
::copysec "sourcefolder" "destination folder"
if not "%1" == "" (
set "source=%1") else (
set /p "source=Source folder: ")
if not "%2" == "" (
set "destination=%2") else (
set /p "destination=Destination folder: ")
if not exist "%destination%" (
echo/Destination folder %source% not found&pause>nul&exit/b)
if exist "%source%" (
pushd "%source%") else (
echo/Source folder %source% not found&pause>nul&exit/b)
set /a count=0
for %%f in (*.*) do (
CALL:PROCESS "%%f")
echo/Finished. %count% files copied
popd&exit/b
:PROCESS file
cls
if "%~x1" == "" (exit/b)
echo/Full path: %~f1&echo/Disk: %~d1
echo/Name: %~n1&echo/Extension: %~x1
echo/Attributes: %~a1&echo/Time %~t1
echo/Size: %~z1 bytes&echo/
set /p "choice=Do you want to copy %1? [Y/N] "
if /i "%choice%" == "y" (
Goto Y)
echo/Skipped&timeout 2 1>nul&exit/b
:Y
copy "%~1" "%destination%\%~1" >nul || GOTO FAIL
attrib +R "%destination%\%~1" >nul || GOTO FAIL
:NEXT
set /a count=count+1
echo/Precess sucefull!&timeout 2 1>nul&exit/b
:FAIL
echo/Failed to copy %~1
pause>nul
exit/b
如果要复制所有子文件夹的所有文件,可以使用/ r 将其保存为copysec.bat。