I have two files say Report.csv Reference.csv
I want to write a Script will reference the Report-ID in the report file names and cross-reference with Reference file data to determine the folder location to move the report.
For eg: Report.csv
R-00001.csv
Data in Reference.csv as below:
ReportID CompanyName
R-00001 BB Trust
R-00002 AA Trust
R-00003 ZZ Trust
R-00004 Canada Inc.
Here in the above, we could see that file name of Report.csv & the first cell value in the Reference.csv is same.
After lookup, the R-00001.csv file needs to be moved to "BB Trust" folder
Likewise, for each of the Report file, same procedure needs to be followed
Please help, it would simplify my work
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))