Reputation: 19
Currently I have a large number (about 10000) of images in a directory (no subfolders), and I need to catalogue them in a csv file. The image filenames are laid out as below:
p000001_06.jpg
p000001_05.jpg
p000001_04.jpg
p000001_03.jpg
p000001_02.jpg
p000001_01.jpg
f000005_11.jpg
f000004_11.jpg
f000003_11.jpg
f000002_11.jpg
f000001_01.jpg
Taking the first image as an example, I would need to get it into the following 5-column format:
p000001_06.jpg,p000001_06,p,000001,06
I have put together the script for the first two columns (see below):
(for %%F in (*) do @echo "%%~nxF",%%~nF) >imageExport.csv
However, I have been floundering around trying to get the rest of it right. I'm pretty sure that it is to do with delimiters and tokens, and I have been tinkering and tinkering but am just not getting it. Would really appreciate the help, as it is not my area of expertise. I also need to work out how to add column headings, but if that confounds matters it's not pressing. Many thanks
Upvotes: 0
Views: 43
Reputation: 56155
delimiters and tokens don't help here. But as your files all have a common format (Xnnnnnn_nn.XXX
) you can use simple string substitution. Also adding a header is easy:
@echo off
setlocal enabledelayedexpansion
REM create header:
echo filename,name,letter,number,whatever>imageExport.csv
(for %%F in (*.jpg) do (
set name=%%~nF
echo %%~nxF,%%~nF,!name:~0,1!,!name:~1,6!,!name:~8,2!
)) >>imageExport.csv
Upvotes: 2