Batch file – file name extract

batch file

I can get the jpg file names extracted to a text file using :

for  %%a in (*.jpg) do echo %%a >> get_files.txt

and this is the output :

Seedling-Acacia-Acinacea-Gold-Dust-Wattle-2-months.jpg

Seedling-Acacia-Acinacea-Gold-Dust-Wattle-6-months.jpg

now I want to output the file name with this path "/images/SeedlingDatabase/" and the output will be :

/images/SeedlingDatabase/Seedling-Acacia-Acinacea-Gold-Dust-Wattle-2-months.jpg

/images/SeedlingDatabase/Seedling-Acacia-Acinacea-Gold-Dust-Wattle-6-months.jpg

Any help appriciated. Thank you

Best Answer

for full path (with drive):

for %%a in (*.jpg) do @echo %%~fa

for path only (without file name and drive):

for %%a in (*.jpg) do @echo %%~pa

you can also prepend \images\SeedlingDatabase\ to the variable value making it:

for %%a in (*.jpg) do @echo \images\SeedlingDatabase\%%a

but i don't think that's exactly what you need

note: remove the extra % in local for variables when issuing the command directly without putting the code in scripts

Related Question