我的目录中有数千个文件(.pdf、.xls、.doc),它们都有相似的命名约定(“类型”始终是常量字符串,即:账单或发票);
帐户名称_帐号_type.pdf
帐户名称_ 帐号_type.doc
帐户名称_帐号_type.xls
手头的任务是接收帐户名和帐号的随机列表(“类型”始终是常量,即:帐单、发票、运输或订单,它们的格式各不相同)并将它们从目录 A 移至目录 B。我可以将列表放入 .csv 文件中以匹配账户名_账户号_type.
我一直在尝试创建一个 powershell 脚本来引用 accountname_accountnumber 并将这些项目从目录 A 移动到目录 B,但没有成功。
SAMPLE我发现了一些更简单的东西,但我希望能够编辑它以创建新的目标,并且如果从此列表中找不到文件则不会停止。另外,如果我可以从 .txt 列表中选择这个选项,我认为这会比粘贴所有内容更容易。
$src_dir = "C:\DirA\"
$dst_dir = "D:\DirB-mm-dd-yyyy\" #This code requires the destination dir to already be there and I need to have the code output a new Directory, it could output based on date script run that would be amazing
$file_list = "accountname1_accountnumber001_type", #If I can select to import csv here
"accountname2_accountnumber002_type",
"accountname3_accountnumber003_type",
"accountname4_accountnumber004_type",
"accountname5_accountnumber005_type",
"accountname6_accountnumber006_type"
foreach ($file in $file_list) #This errors out and stops the script if the file is not located in source and I need to have the script continue and move on, with hopefully an error output
{
move-Item $src_dir$file $dst_dir
}
它们可以是任何文件格式,我试图让代码仅匹配帐户名和帐户号,因为这两个将定义确切的客户。无论是发票、账单还是运输并不重要,因为他们希望移动与该客户关联的所有文件。
例如,每个帐户可能有 4 个,并且类型格式可能与 pdf、doc 和 xls 不同,我需要根据前两个指示符(帐户名称、帐户编号)移动所有文件。
alice_001_invoice.pdf
alice_001_billing.doc
alice_001_shipping.pdf
alice_001_order.xls
乔治_245_发票.pdf
乔治_245_billing.doc
乔治_245_shipping.pdf
乔治_245_order.xls
Bob_876_invoice.pdf
Bob_876_billing.doc
Bob_876_shipping.pdf
Bob_876_order.xls
Horman_482_invoice.pdf
Horman_482_billing.doc
Horman_482_shipping.pdf
Horman_482_order.xls
CSV:
账户名、账号
爱丽丝,001
乔治,245
Bob,876
霍曼,482