3

使用 Windows Batch For Loop 的大多数示例都是关于使用“IN”的。

FOR %%A IN (1 2 3 4) DO ECHO %%A

我需要使用 NOT IN 代替。当我键入以下内容时:

FOR %%A NOT IN (1 2 3 4) DO ECHO %%A

它说“当时没有预料到”。

谢谢

4

4 回答 4

0
for %%F in ('dir /b /a-d "somepath\*"^|findstr /vilxg:"exclusions.txt"') do echo %%F

Since in comments you say you want to move files not in a list, you should try using ROBOCOPY. Check out the /MOV and /XF options. It should allow you to do exactly what yo want in a more direct manner. Type robocopy /? from the command line for help. There are a ton of options to navigate, so it might take a while to get the exact result you want. But the command is extremely powerful and worthwhile.

于 2013-09-03T14:20:52.810 回答
0

根据您上面的评论,您想要一个“没有这些文件的 DIR”吗?那么这应该工作:

> 键入 donotuse.txt

alpha.txt
beta.exe
gamma.cmd

> 键入 t.bat

@dir /b | findstr /b /e /v /i /l /g:donotuse.txt

> 目录 /b

albetade.txt
alpha.exe
alpha.txt
beta.exe
donotuse.txt
gamma.cmd
t.bat

> 吨

albetade.txt
alpha.exe
donotuse.txt
t.bat

>

编辑:dbenham 是对的。添加/i /l到我的代码中。

于 2013-09-03T13:02:00.650 回答
0

比尔,这可能会满足你的需要,或者给你一个提示......

@echo off
for /f "delims=" %%a in (' type "file.txt" ') do (
if not exist "c:\target\%%a" move "%%a" "c:\target"
)
于 2013-09-03T14:54:31.517 回答
0

我有同样的问题,但没有解决方案。所以......这是我个人的简单解决方案:

@echo off
rem set the path to check
set sourcePath=C:\Program Files (x86)\MySoftware
set destPath=c:\temp\MySoftware-StrangerFiles
set tempPath=c:\temp
set currentFilesListTxtFileName=MySoftware-allfiles.txt
set correctFilesListTxtFileName=MySoftware-correctFilesList.txt
set moveFilesListTxtFileName=MySoftware-moveFilesList.txt
echo Move not allowed files in a different path
cd "%sourcePath%"
mkdir %destPath%

call :correctFilesList

dir /B > c:\temp\MySoftware-allfiles.txt
findstr /V /G:%tempPath%\%correctFilesListTxtFileName% %tempPath%\%currentFilesListTxtFileName% > %tempPath%\%moveFilesListTxtFileName%
for /f "delims=" %%a in (' type "%tempPath%\%moveFilesListTxtFileName%" ') do move %%a %destPath%
pause

:correctFilesList
rem files whitelist
rem correctfiles can be changed with "dir /B path>>c:\temp\correctFilesList.txt" from a correct source. Or you can generate a list of correct files via command as below.
echo correctfile1.dll>> %tempPath%\%correctFilesListTxtFileName%.txt
echo correctfile2.log.xml>> %tempPath%\%correctFilesListTxtFileName%.txt
echo correctfile2.log.xml>> %tempPath%\MySoftware-correctFilesList.txt
于 2020-06-01T14:38:23.327 回答