Pergunta

I would like to use a different method for me to whitelist my files from being deleted from a folder.

The concept would be to add the file names into a text file to keep it from being deleted. How do I accomplish this? So far this is what I have. I just don't want to go through all the brackets in the future:

for %%i in ("universe\*.world") do (

if /i not "%%~nxi"=="alpha_-47760677_13528428_3442937_2_8.world" (
if /i not "%%~nxi"=="alpha_-91359870_-23985140_-2679670_4_2.world" (
if /i not "%%~nxi"=="beta_-10_-18_-22519438_9.world" (
if /i not "%%~nxi"=="alpha_71479806_30568958_-29806832_11_4.world" (
if /i not "%%~nxi"=="alpha_49727000_-95701173_-4914589_9.world" (
if /i not "%%~nxi"=="gamma_-98261021_73451017_-13446340_2_5.world" (
if /i not "%%~nxi"=="test2.world" (
if /i not "%%~nxi"=="test2.world" (
if /i not "%%~nxi"=="test2.world" (
if /i not "%%~nxi"=="test2.world" (
if /i not "%%~nxi"=="test2.world" (
if /i not "%%~nxi"=="test2.world" (
del /q "%%i"

)))))))))))))
)

Lets say the text file I want to pull the list from is whitelist.txt, and each line has the file name I am keeping:

alpha_-47760677_13528428_3442937_2_8.world
alpha_-91359870_-23985140_-2679670_4_2.world
beta_-10_-18_-22519438_9.world
alpha_71479806_30568958_-29806832_11_4.world
alpha_49727000_-95701173_-4914589_9.world
gamma_-98261021_73451017_-13446340_2_5.world

Or maybe even without adding ".world" extension?

I've tried using this but when it's looking for files not to delete, it gets cut off due to "File not found - C:\Program" due to the nature of the space in Program Files (x86) having spaces:

for /f %%i in ("whitelist.txt") do attrib +r %%i & del /q "universe\*.world" & for /f %%i in ("whitelist.txt") do attrib -r %%i
Foi útil?

Solução

@ECHO OFF
SETLOCAL
FOR %%i IN (".\*.world") DO (
  TYPE q20769624.txt|FINDSTR /i /b /e /L /c:"%%~ni"  >NUL
 IF ERRORLEVEL 1 ECHO DEL "%%i"
)
GOTO :EOF

Where q20769624.txt is your whitelist file, without the .world appendix.

This batch will simply echo the files to delete. Remove the ECHO keyword before the DEL to activate the delete function after testing.

Amended to allow spaces in the filename and no newline at end of data file.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top