gnuplot:文件路径中的空格
gnuplot: spaces in file path
使用带空格的文件名的正确程度如何?
我的代码:
files = system("dir /b \"d:\data\my data\*.dat\"")
do for [name in files]{
inputPath = "d:/data/my data/".name
outputPath = "d:/data/".name.".png"
set output outputPath
plot inputPath using 1:3 with lines ls 1 notitle
}
如果文件名中有空格,则脚本无法正常运行。
例如:
d:/data/my data/data1.csv - 全部正确
d:/data/my data/data 2.csv - 错误,创建了 0 大小的文件 "data.png" 而未创建图表
如何解决这个问题?
发现问题:
命令 do for [name in files]
将文件名列表分成单词(space 作为分隔符),而不是分成行(\r\n 作为分隔符)
因此,有必要select列表中的字符串,而不是单词。
基本上,您需要将 "\n"
替换为 space
并将您的文件名放在引号 ''
中。
以下代码可能是执行此操作的一种方法。
顺便说一下,您的代码会从 "Data1.csv" 生成 "Data1.dat.png" 之类的输出名称,而不是 "Data1.png"。还要注意单引号和双引号的区别。
### File list with space in filenames (Windows)
reset session
InputPath = 'D:\data\my data\'
OutputPath = 'D:\data\'
SearchExp = 'dir /b "' . InputPath . '*.dat"'
# print SearchExp
LIST = system(SearchExp)
# print LIST
LIST = LIST eq "" ? LIST : "'".LIST."'" # add ' at begining and end
FILES = ""
do for [i=1:strlen(LIST)] {
FILES = (LIST[i:i] eq "\n") ? FILES."' '" : FILES.LIST[i:i]
}
# print FILES
print sprintf("The list contains %d files", words(FILES))
do for [FILE in FILES] {
InputFile = InputPath.FILE
OutputFile = OutputPath.FILE[1:strlen(FILE)-4].".png"
print InputFile
print OutputFile
# or plot your files
}
### end of code
使用带空格的文件名的正确程度如何?
我的代码:
files = system("dir /b \"d:\data\my data\*.dat\"")
do for [name in files]{
inputPath = "d:/data/my data/".name
outputPath = "d:/data/".name.".png"
set output outputPath
plot inputPath using 1:3 with lines ls 1 notitle
}
如果文件名中有空格,则脚本无法正常运行。 例如:
d:/data/my data/data1.csv - 全部正确
d:/data/my data/data 2.csv - 错误,创建了 0 大小的文件 "data.png" 而未创建图表
如何解决这个问题?
发现问题:
命令 do for [name in files]
将文件名列表分成单词(space 作为分隔符),而不是分成行(\r\n 作为分隔符)
因此,有必要select列表中的字符串,而不是单词。
基本上,您需要将 "\n"
替换为 space
并将您的文件名放在引号 ''
中。
以下代码可能是执行此操作的一种方法。
顺便说一下,您的代码会从 "Data1.csv" 生成 "Data1.dat.png" 之类的输出名称,而不是 "Data1.png"。还要注意单引号和双引号的区别。
### File list with space in filenames (Windows)
reset session
InputPath = 'D:\data\my data\'
OutputPath = 'D:\data\'
SearchExp = 'dir /b "' . InputPath . '*.dat"'
# print SearchExp
LIST = system(SearchExp)
# print LIST
LIST = LIST eq "" ? LIST : "'".LIST."'" # add ' at begining and end
FILES = ""
do for [i=1:strlen(LIST)] {
FILES = (LIST[i:i] eq "\n") ? FILES."' '" : FILES.LIST[i:i]
}
# print FILES
print sprintf("The list contains %d files", words(FILES))
do for [FILE in FILES] {
InputFile = InputPath.FILE
OutputFile = OutputPath.FILE[1:strlen(FILE)-4].".png"
print InputFile
print OutputFile
# or plot your files
}
### end of code