Nun können versuchen, ein weiterer alberner Weg, um eine Liste zu lesen. Ich habe diese Technik von Aacini auf den Dostips.com Foren gehört. Es gibt eine maximale Anzahl an Zeichen, die Sie für den SET-Befehl haben können, so dass es beim Versuch, vielen Einträgen zuzuordnen, fehlschlägt.
@echo off
setlocal EnableDelayedExpansion
set str=file1.txt?^
file2.txt?^
file 4.txt?^
file5.txt?^
some other file.jpg?^
and yet another file.mp3?
for /F "delims=" %%s in (^"!str:?^=^
%= Replace question with linefeeds =%
!^") do (
echo %%~s
)
pause
Ausgabe
file1.txt
file2.txt
file 4.txt
file5.txt
some other file.jpg
and yet another file.mp3
Press any key to continue . . .
Getestet habe ich alle drei Sätze von Code und weil die Datensätze der Zeitdifferenz so klein ist, ist auf meiner Maschine zu vernachlässigen. Ich habe 36 Zeilen für den Datensatz verwendet und den Code zehnmal durchlaufen.
Wally time is 0.78 Seconds
Squashman time is 0.78 Seconds
Magoo time is 0.78 Seconds
Wally time is 0.79 Seconds
Squashman time is 0.79 Seconds
Magoo time is 0.78 Seconds
Wally time is 0.78 Seconds
Squashman time is 0.78 Seconds
Magoo time is 0.78 Seconds
Wally time is 0.78 Seconds
Squashman time is 0.78 Seconds
Magoo time is 0.79 Seconds
Wally time is 0.78 Seconds
Squashman time is 0.62 Seconds
Magoo time is 0.78 Seconds
Wally time is 0.78 Seconds
Squashman time is 0.78 Seconds
Magoo time is 0.94 Seconds
Wally time is 0.79 Seconds
Squashman time is 0.78 Seconds
Magoo time is 0.78 Seconds
Wally time is 0.78 Seconds
Squashman time is 0.78 Seconds
Magoo time is 0.94 Seconds
Wally time is 0.79 Seconds
Squashman time is 0.78 Seconds
Magoo time is 0.78 Seconds
Wally time is 0.78 Seconds
Squashman time is 0.78 Seconds
Magoo time is 0.78 Seconds
Press any key to continue . . .
easer/besser definieren. Leichter zu lesen/zu pflegen/zu verstehen für Sie/spätere Benutzer/Computer? In Ihrem Code 'usebackq' und die Klammern um den if sind nicht notwendig. – LotPings
Es ist definitiv einfacher, sowohl den Programmcode als auch den Datensatz zu pflegen, wenn sie sich in separaten Dateien befinden. Aber sie scheinen langsamer zu sein. Deshalb frage ich mich, ob es eine andere Möglichkeit gibt, die Daten zu lesen. –
Es gibt keine Notwendigkeit für die "wenn vorhanden". Und Sie erzwingen zwei Festplattenlesevorgänge und eine Festplatte schreiben statt eins und eins. Löschen Sie einfach die Datei. Wenn es nicht existiert, wird sich nichts ändern, wenn es dies tut, wird es gelöscht. – Freddie