Consegui fazer isso funcionar com os resultados explicados usando um arquivo de lista de exemplos com nomes de domínio que coloquei na lista. Eu usei o FOR /F "USEBACKQ TOKENS=*" %%A IN ("filelist")
apenas assim.
Eu tento usar os loops USEBACKQ
e TOKENS=*
nos FOR / F que leem de uma lista de arquivos pelas razões que listei abaixo na seção Script Logic Explained , leia isso e teste para confirmar.
Exemplo de lote de trabalho
FOR /F "USEBACKQ TOKENS=*" %%A IN ("c:\users\SCTMP000\server.txt") DO (ECHO %%~A)
Script Logic Explained
The
USEBACKQ
option used in the FOR loop will ensure the file list can still be read if the file list name or it's path has any spaces in it and you need to double quote the file list path
- E.g.
SET FileList=C:\Folder Name\File List.txt
- Without the
USEBACKQ
the FOR loop would error out in a case like thisThe
TOKENS=*
option used in the FOR loop will ensure the the entire value is returned as it's read from the file list even if that value has a space in it even though that should not be applicable to domains this is why you'd use it
E.g. File list has a value of
"test my file.txt"
so the value has a space on a line
- Without the
TOKENS=*
the FOR loop would only return the value portion of that line before the first space and not the value as expected (i.e."test"
)Using these options even when not needed does not seem to cause any harm and should you ever introduce such a value or variable into the mix of the script, it'd already be able to handle such cases accordingly.
Mais recursos
- FOR / F
- Solução de problemas do Agendador de Tarefas Tarefas
-
FOR /?
tokens=x,y,m-n - specifies which tokens from each line are to be passed to the for body for each iteration. This will cause additional variable names to be allocated. The m-n form is a range, specifying the mth through the nth tokens. If the last character in the tokens= string is an asterisk, then an additional variable is allocated and receives the remaining text on the line after the last token parsed. usebackq - specifies that the new semantics are in force, where a back quoted string is executed as a command and a single quoted string is a literal string command and allows the use of double quotes to quote file names in file-set.