Page 1 of 1

Please help, creating DOS batch file to create csv from DIR

Posted: 02 Sep 2010 01:20
by aown61
Hi guys i've created the below batch file to create a csv fil from a dir command.

Code: Select all

@echo ImageId, ImageFilePath >> "\\ptdckbox01\d$\Bi Projects\Inputs\RE\Audit_Pics\audit_pics_dir.csv"
dir "\\ptdckbox01\d$\Bi Projects\Inputs\RE\Audit_Pics\" /b /s >> "\\ptdckbox01\d$\Bi Projects\Inputs\RE\Audit_Pics\audit_pics_dir.csv"
exit


which outputs like this
    ImageId,ImageFilePath
    \\ptdckbox01\d$\BI Projects\Inputs\RE\Audit_pics\1432_10_2039632_646972_pic_20100412144137.JPG
    \\ptdckbox01\d$\BI Projects\Inputs\RE\Audit_pics\1432_10_2039632_647019_pic_20100412145052.JPG
    \\ptdckbox01\d$\BI Projects\Inputs\RE\Audit_pics\1432_10_2039632_647020_pic_20100412151126.JPG
    \\ptdckbox01\d$\BI Projects\Inputs\RE\Audit_pics\1432_10_2039632_647021_pic_20100412142038.JPG
    \\ptdckbox01\d$\BI Projects\Inputs\RE\Audit_pics\1432_10_2039632_647032_pic_20100412132722.JPG
    \\ptdckbox01\d$\BI Projects\Inputs\RE\Audit_pics\1432_10_2039632_647075_pic_20100412145413.JPG
    \\ptdckbox01\d$\BI Projects\Inputs\RE\Audit_pics\1432_10_2039632_647078_pic_20100412150103.JPG

this is fine but i need to make it look like this...

    ImageId,ImageFilePath
    1432_10_2039632_646972_pic_20100412144137.JPG,\\ptdckbox01\d$\BI Projects\Inputs\RE\Audit_pics\1432_10_2039632_646972_pic_20100412144137.JPG
    1432_10_2039632_647019_pic_20100412145052.JPG,\\ptdckbox01\d$\BI Projects\Inputs\RE\Audit_pics\1432_10_2039632_647019_pic_20100412145052.JPG
    1432_10_2039632_647020_pic_20100412151126.JPG,\\ptdckbox01\d$\BI Projects\Inputs\RE\Audit_pics\1432_10_2039632_647020_pic_20100412151126.JPG
    1432_10_2039632_647021_pic_20100412142038.JPG,\\ptdckbox01\d$\BI Projects\Inputs\RE\Audit_pics\1432_10_2039632_647021_pic_20100412142038.JPG
    1432_10_2039632_647032_pic_20100412132722.JPG,\\ptdckbox01\d$\BI Projects\Inputs\RE\Audit_pics\1432_10_2039632_647032_pic_20100412132722.JPG
    1432_10_2039632_647075_pic_20100412145413.JPG,\\ptdckbox01\d$\BI Projects\Inputs\RE\Audit_pics\1432_10_2039632_647075_pic_20100412145413.JPG
    1432_10_2039632_647078_pic_20100412150103.JPG,\\ptdckbox01\d$\BI Projects\Inputs\RE\Audit_pics\1432_10_2039632_647078_pic_20100412150103.JPG


Any suggestions? I just cant work out how i can call the same DIR and kind of concat it to the output .csv

If you can help you will be a life saver!
Regards
-Andy

Re: Please help, creating DOS batch file to create csv from

Posted: 02 Sep 2010 02:43
by orange_batch
There may be a better solution, but based on your code (btw there is spacing discrepancy which I'm sure you know)...

Code: Select all

@echo ImageId, ImageFilePath >> "\\ptdckbox01\d$\Bi Projects\Inputs\RE\Audit_Pics\audit_pics_dir.csv"
for /f "delims=" %%x in ('dir "\\ptdckbox01\d$\Bi Projects\Inputs\RE\Audit_Pics\" /b /s') do (
echo %%~nxx,%%x>> "\\ptdckbox01\d$\Bi Projects\Inputs\RE\Audit_Pics\audit_pics_dir.csv"
)
exit


Not tested. I don't know if FOR works fine on network locations, but to be safe it's parsing the line as a string. Luckily ~nx (enhanced references) works on strings too.

Re: Please help, creating DOS batch file to create csv from

Posted: 02 Sep 2010 03:14
by aown61
You sir are a genius!
Thank you very much, exactly what i was after :)
-Andy

Re: Please help, creating DOS batch file to create csv from

Posted: 02 Sep 2010 03:25
by orange_batch
Image