【发布时间】:2021-05-22 04:12:54
【问题描述】:
我需要根据从 location3 的文本文件名中提取的子字符串(在最后一个和倒数第二个 '.' 之间)将 pdf 文件从 location1 移动到 location2。我无法在运行时重命名 location1 的 pdf 文件,因为它有数十万个 pdf 文件,我只需要匹配子字符串模式的几个。
位置 3:
A_b_c_d_e_f_1.2.3.4.5.txt
G_h_i_j_k_6.7.8.9.txt
l_m_n_o_p_2.7.8.4.txt
位置 1:
5_rha_thye_lej.pdf
9_tyoe_hslel_hlssls.pdf
4_shl_heoe_keie_ekye.pdf
我实现了从 txt 文件名中获取子字符串,但是移动匹配模式的 pdf 导致了问题。
$files = Get-ChildItem "location3" -Filter *.txt
forEach ($n in $files) {
$substring = $n.Name.split(".")[-2]
write-host $substring }
Move-Item (Join-Path location1\$substring) -Destination location2
【问题讨论】:
标签: powershell pdf split substring