分割文件的名称和提取时间长生不老药



我在这个模式中有将近100k个文件。

["192.168.1.225_01_20190316070000734_TIMING.jpg",
"192.168.1.225_01_20190316071000736_TIMING.jpg",
"192.168.1.225_01_20190316072000736_TIMING.jpg",
"Camera_1_615696208_20190318075200317_TIMING.jpg",
"Camera_1_615696208_20190318080200322_TIMING.jpg",
"Camera_1_615696208_20190318082200326_TIMING.jpg",
"camera2_615696156_20190318080000375_TIMING.jpg",
"camera2_615696156_20190318081000377_TIMING.jpg",
"camera2_615696156_20190318093000394_TIMING.jpg"]

它们大多在我正在进行File.ls(@picture_directory)的本地驱动器中

所有这些都是3台相机的照片,它们的标识符为

cameras = %{
"Camera_1_615696208_" => "nch1-zcpes",
"camera2_615696156_" => "nch2-zkhcy",
"192.168.1.225_01_" => "nch3-ipljs"
}

左边是日期和时间之前的前缀。。右侧是标识符。

我想做的是制作3-tuple。像这样。。

[filename, datetime, indentifier]

假设在一个文件中。

["192.168.1.225_01_20190316070000734_TIMING.jpg", "20190316070000734", "nch3-ipljs']

到目前为止,我已经尝试过了。

defmodule EvercamMedia.Nch do
@picture_directory "/home/junaid/Desktop/NCH"
def move do
cameras = %{
"Camera_1_615696208_" => "nch1-zcpes",
"camera2_615696156_" => "nch2-zkhcy",
"192.168.1.225_01_" => "nch3-ipljs"
}
File.ls!(@picture_directory)
|> Enum.sort
|> Enum.map(fn file ->
Enum.each(cameras, fn cam ->
{prefix, exid} = cam
with true <- String.contains?(file, prefix) do
datetime = file |> String.trim_leading(prefix) |> String.trim_trailing("_TIMING.jpg")
[file, datetime, exid]
else
_ -> :noop
end
end)
end)
end
end

但这只返回一个列表:好的。。

这将从每个文件名中解析日期,并将其放入一个列表中,就像您的示例一样。

[
"192.168.1.225_01_20190316070000734_TIMING.jpg",
"192.168.1.225_01_20190316071000736_TIMING.jpg",
"192.168.1.225_01_20190316072000736_TIMING.jpg",
"Camera_1_615696208_20190318075200317_TIMING.jpg",
"Camera_1_615696208_20190318080200322_TIMING.jpg",
"Camera_1_615696208_20190318082200326_TIMING.jpg",
"camera2_615696156_20190318080000375_TIMING.jpg",
"camera2_615696156_20190318081000377_TIMING.jpg",
"camera2_615696156_20190318093000394_TIMING.jpg"
]
|> Enum.map(fn
"192.168.1.225_01_" <> <<date::binary-size(17)>> <> _ = file -> [file, date, "nch3-ipljs"]
"Camera_1_615696208_" <> <<date::binary-size(17)>> <> _ = file -> [file, date, "nch1-zcpes"]
"camera2_615696156_" <> <<date::binary-size(17)>> <> _ = file -> [file, date, "nch2-zkhcy"]
end)

输出:

[
["192.168.1.225_01_20190316070000734_TIMING.jpg", "20190316070000734",
"nch3-ipljs"],
["192.168.1.225_01_20190316071000736_TIMING.jpg", "20190316071000736",
"nch3-ipljs"],
["192.168.1.225_01_20190316072000736_TIMING.jpg", "20190316072000736",
"nch3-ipljs"],
["Camera_1_615696208_20190318075200317_TIMING.jpg", "20190318075200317",
"nch1-zcpes"],
["Camera_1_615696208_20190318080200322_TIMING.jpg", "20190318080200322",
"nch1-zcpes"],
["Camera_1_615696208_20190318082200326_TIMING.jpg", "20190318082200326",
"nch1-zcpes"],
["camera2_615696156_20190318080000375_TIMING.jpg", "20190318080000375",
"nch2-zkhcy"],
["camera2_615696156_20190318081000377_TIMING.jpg", "20190318081000377",
"nch2-zkhcy"],
["camera2_615696156_20190318093000394_TIMING.jpg", "20190318093000394",
"nch2-zkhcy"]
]

相关内容

  • 没有找到相关文章