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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
aown61
Posts: 4
Joined: 02 Sep 2010 01:10

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

#1 Post by aown61 » 02 Sep 2010 01:20

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

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

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

#2 Post by orange_batch » 02 Sep 2010 02:43

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.

aown61
Posts: 4
Joined: 02 Sep 2010 01:10

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

#3 Post by aown61 » 02 Sep 2010 03:14

You sir are a genius!
Thank you very much, exactly what i was after :)
-Andy

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

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

#4 Post by orange_batch » 02 Sep 2010 03:25

Image

Post Reply