简体   繁体   中英

How can I Delete Files That Do Not Contain Certain Characters Using Windows Batch File?

How can I delete files that do not end with the pattern .PDF_*.pdf ?

AA00A6E2.PDF
AA00A6E3.PDF
AA00A6E3.PDF_01.pdf
AA00A6E3.PDF_02.pdf
AA00A6E3.PDF_03.pdf

I have been trying all sorts of variations around the following syntax:

FOR %%F IN (%varFolderSource%\*.*) DO IF NOT "%%~xF" == "*_*" DEL /F /S "%%F"

But I can't seem to crack it.

%varFolderSource% is a folder path: C:\Temp etc.

I am running this in a Windows 7 batch file.

For /f "delims=" %A in ('dir /b /a-d ^|findstr /i /v /e /r "\.PDF_[a-z0-9]*\.pdf"') do echo %A

Type

for /?
findstr /?

In a batch file use %%A rather than %A at command prompt.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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