【发布时间】:2018-05-06 21:15:18
【问题描述】:
我有两个文件,比如 Report.csv Reference.csv
我想编写一个脚本,将引用报表文件名中的 Report-ID 并与 Reference 文件数据交叉引用以确定移动报表的文件夹位置。
例如:Report.csv
R-00001.csv
Reference.csv 中的数据如下:
ReportID CompanyName
R-00001 BB Trust
R-00002 AA Trust
R-00003 ZZ Trust
R-00004 Canada Inc.
在上面,我们可以看到 Report.csv 的文件名和 Reference.csv 中的第一个单元格值是相同的。
查找后,需要将 R-00001.csv 文件移至“BB Trust”文件夹
同样,对于每个报告文件,需要遵循相同的程序
请帮忙,这会简化我的工作
echo off
:: Gets the filenames to textfile
dir /b "C:\Users\Reports\" >
reportnames.txt
:: Compare two files to look for
the matching ReportID and get the
Companyname value from
Reference.csv & create a folder in
that name and move the report
files to that corresponding folder
for /f "tokens=1" %%i in
(Reportnames.txt) do
@findstr "%%i," Reference.csv >nul
& If errorlevel 0 if not
errorlevel 1 (for /f "tokens=2"
%%m in ('findstr /i /L "%%i,"
Reference.csv') do ( cd
C:\Users\Archive\ & mkdir
%%m))
【问题讨论】:
标签: batch-file scripting command