Moving files from CSV to new folder along with path.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
cph
Posts: 1
Joined: 16 Feb 2019 01:19

Moving files from CSV to new folder along with path.

#1 Post by cph » 16 Feb 2019 01:58

i have a code which will generate CSV file and than move to new sub folders.

@echo off
setlocal enableDelayedExpansion

set root=D:\Testing
set csv=D:\Output\testing.csv

set line=
set curpath=
set new=
>nul copy nul: %csv%

for /f %%F in ('dir /s/b /on %root%\*.tif') do (
if not "!curpath!" == "%%~dpF" set new=y
set fname=%%~nxF
if not "!fname:-=!" == "!fname!" set new=y

if defined new (
if defined line echo !line!>> %csv%
set line=%%~dpF
set new=
)

set line=!line!,%%~nxF
set curpath=%%~dpF
)
if defined line echo !line!>> %csv%
timeout 2>nul
set /a cnt=1
for /f "tokens=1-3 %%i in (%csv%) do (
mkdir %%ifolder!cnt!>nul
move %%i%%j %%ifolder!cnt!
move %%i%%k %%ifolder!cnt!
set /a cnt+=1
)

This code will generate a CSV based on DIR (all fine here)
Image
Need your help : The CSV output contains more than 3 file names in a row, but as per code it is taking only 2 files and rest are omitted.I have tried changing the Tokens but no result.
What will be the alternate method.
Example : 001-001.tif 002.tif 003.tif Row 1 in this case 003.tif is omitted.


2nd Question : The folders needs to get generated in "D:\Output\" but currently it is getting generated in "D:\Testing"
Let me explain : There is a folder named 120 which contains 100 tiff files, these are pulled to CSV based on a parameter "-" Hyphen,if there is a file name which contains hyphen it is taken to the new row of csv.
Example : 001-001.tif 002.tif 003.tif Row 1
004-004.tif 005.tif Row 2

3rd Question: When the new folder are created, it should re write the CSV against the original path to validate, so that we can identify folder no created against which row of csv file.
Example: "D:\Testing\120" 001-001.tif 002.tif 003.tif "Folder 1"

Little lengthy, but need to make minor corrections to make the code successful.
Attachments
Testing Sample.jpg
Sample
Testing Sample.jpg (98.21 KiB) Viewed 18346 times

Post Reply