sifar786 wrote:this does not create the folders, subfolders and copy (move) the files to their respective folders.
indeed, so here we go:
Code: Select all
@echo off&setlocal
set "startfolder=%~1" &rem parameter #1
set "ClassID_ID_List=%~2" &rem parameter #2
set "CSVfile=%~3" &rem parameter #3
set "CSVdelim= " &rem, delimiter for output, default <tab>
rem ^---< put your <tabspace> there
cd /d "%startfolder%"
if not exist "%ClassID_ID_List%" echo("%ClassID_ID_List%" not found&goto:eof
for /f "usebackqtokens=2" %%i in ("%ClassID_ID_List%") do (
for %%f in ("%%i_*") do set /a %%~xf=%%~xf + 1 2>nul
)
set "." >nul 2>&1 || (echo(no files from "%ClassID_ID_List%" found in "%startfolder%"&goto:eof)
((for /f "delims==." %%i in ('set "."') do <nul set/p"=%%i%CSVdelim%")&echo(
(for /f "tokens=2delims==" %%i in ('set "."') do <nul set/p"=%%i%CSVdelim%")&echo(
)>"%CSVfile%"
for /f "usebackqtokens=1,2" %%i in ("%ClassID_ID_List%") do (
if not exist "%%i\%%j\" md "%%i\%%j"
move "%%j_*" "%%i\%%j"
)
The script overwrites all files in the subfolders, if there any exists.
Example, input:
Code: Select all
C:\USERS\SIFAR786
└───desktop
10001_ANU.jpg
10001_COE.jpg
10001_COE.pdf
10001_ENU.jpg
10001_ENU.mdb
10001_ENU.pdf
10002_ENI.jpg
10002_EVS.cls
10002_TAS.docx
10002_TNU.png
10003_NIO.xlsm
10003_NOE.doc
10003_RAS.ppt
10004_GAR.xls
ClassID_ID_List.txt
Output:
Code: Select all
C:\USERS\SIFAR786
└───desktop
│ ClassID_ID_List.txt
│ Out.csv
│
├───1
│ ├───10001
│ │ 10001_ANU.jpg
│ │ 10001_COE.jpg
│ │ 10001_COE.pdf
│ │ 10001_ENU.jpg
│ │ 10001_ENU.mdb
│ │ 10001_ENU.pdf
│ │
│ └───10004
│ 10004_GAR.xls
│
├───2
│ └───10002
│ 10002_ENI.jpg
│ 10002_EVS.cls
│ 10002_TAS.docx
│ 10002_TNU.png
│
└───3
└───10003
10003_NIO.xlsm
10003_NOE.doc
10003_RAS.ppt
ClassID_ID_List:
Code: Select all
1 10001
1 10004
2 10002
3 10003