繁体   English   中英

如果文件夹包含.txt文件,然后将其复制到其他位置,如何使用Batch检出?

[英]How to check out with Batch , if a folder contains a .txt file and then copy the folder into an other location?

我想使用Batch编写脚本。 我想从此脚本中检出它,如果一个文件夹包含文件“ list.txt”,并且该文件是否在该文件夹中,我想在其他位置进行复制。 我写了几行代码,但是没有用。 有任何想法吗?

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

:loop
    for /f %%i in ('dir "C:\Users\ntosis\Desktop\Draft" /ad /o:d /s /b') do ( 
    SET a=%%i
        for /R %%a %%t in (*.txt) do if "%%~nxt"=="list.txt" SET p=%%~dpnxt
        echo !p!

        IF DEFINED %p% ( robocopy C:\Users\ntosis\Desktop\Draft\%a% C:\Users\ntosis\Desktop\Copied\%a% /MOVE /E )
)

echo Folder is empty or does not exist
timeout /t 15
goto loop

目前的问题是第二个循环没有检查正确。

这个怎么样:

for /f %%i in ('dir "C:\Users\ntosis\Desktop\Draft" /ad /o:d /s /b') do ( 
    IF EXIST "%%i\list.txt" (
        robocopy %%i C:\Users\ntosis\Desktop\Copied\ /MOVE /E
    )
)
@echo off setlocal enableextensions disabledelayedexpansion set "source=C:\Users\ntosis\Desktop\Draft" set "target=C:\Users\ntosis\Desktop\Copied" for /l %%t in (0) do ( set "found=" for /d /r "%source%" %%a in (list.txt) do if exist "%%a" ( for %%b in ("%%~dpa.") do ( echo Found "%%a" robocopy "%%~dpa." "%target%\%%~nxb" /move /e ) set "found=1" ) if not defined found ( echo folder is empty or does not exist ) timeout /t 15 )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM