Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file Windows批处理是否有类似于BASIC';s";“数据”;陈述_Batch File - Fatal编程技术网

Batch file Windows批处理是否有类似于BASIC';s";“数据”;陈述

Batch file Windows批处理是否有类似于BASIC';s";“数据”;陈述,batch-file,Batch File,让批处理文件加载长数据列表的最简单方法是什么?现在我从一个单独的文本文件中加载数据,但我怀疑这比将数据与程序代码放在同一个文件中要慢。有没有比我现在做的更好的处理方法,就是: for /f "usebackq delims=" %%g in (list.txt) do (if exist "%%g.jpg" del "%%g.jpg") 这里有一种方法可以满足您的要求: @ECHO关闭 SETLOCAL 设置“数据=” 对于/f“usebackqdelims=“%”中的%%a(“%~f0”)D

让批处理文件加载长数据列表的最简单方法是什么?现在我从一个单独的文本文件中加载数据,但我怀疑这比将数据与程序代码放在同一个文件中要慢。有没有比我现在做的更好的处理方法,就是:

for /f "usebackq delims=" %%g in (list.txt) do (if exist "%%g.jpg" del "%%g.jpg")

这里有一种方法可以满足您的要求:

@ECHO关闭
SETLOCAL
设置“数据=”
对于/f“usebackqdelims=“%”中的%%a(“%~f0”)DO(
如果/i“%%a”==“[enddata]“SET”数据=”
如果定义了数据回送,则在“%%a”上执行命令
如果/i“%%a”==“[数据]”设置“数据=Y”
)
后藤:EOF
[数据]
一些filename.jpg
更多数据.jpg
[完数据]
嗯,太复杂了。显然,可以删除
[enddata]
功能,但这允许灵活性(两个或多个数据段、[data1][data2]等,每个都有自己的数据段末尾)

我怀疑它会比您当前的系统慢,而且更难使用。对于外部文件,您可以使用编辑器(或编程方式)简单地更改该文件,而对于此系统,您需要维护批处理文件本身


它更适合于“固件”式的数据(像服务器列表一样是半永久性的),而不是动态数据,但是你付钱,你自己选择……

好吧,让我们尝试另一种愚蠢的方式来阅读列表。我相信这是从Aacini那里在Dostips.com论坛上得到的。SET命令的最大字符数是允许的,因此当尝试分配给多个条目时,该命令将失败

 @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
输出

file1.txt
file2.txt
file 4.txt
file5.txt
some other file.jpg
and yet another file.mp3
Press any key to continue . . .
我测试了所有三组代码,因为数据集非常小,所以在我的机器上时间差可以忽略不计。我对数据集使用了36行代码,并将代码循环运行了10次

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 . . .

我认为这是最简单的方法:

@echo off

for %%g in (file1  file2  file3  "A long file name with spaces"
            fileN  fileM ) do (
   del "%%~g.jpg"
)

定义更容易/更好。您/以后的用户/计算机更易于阅读/维护/理解?在代码
usebackq
中,if周围的括号不是必需的。如果程序代码和数据集位于不同的文件中,那么维护它们肯定更容易。但它们似乎速度较慢。这就是为什么我想知道是否有其他方法来读取数据。如果存在
,则不需要
。您强制执行两次磁盘读取和一次磁盘写入,而不是一次一次。只需删除文件。如果它不存在,则不会有任何更改,如果它存在,则将被删除。@WallyWalters,您尚未为前两个问题中的任何一个选择答案。谢谢,我想你是对的,但我期待着尝试一下,并为两者都计时。最糟糕的情况是我将学习一种新技术,除非其中一个文件名中有逗号或分号。然后您需要引用所有文件名。