Name: pball Date: November 16, 2007 at 23:16:38 Pacific Subject: Making a list with batch OS: XP CPU/Ram: 2.0 ghz / 1 gig Model/Manufacturer: homemade
Comment:
I want to to be able to output a list using a batch file. I have most of what is needed but I cannot add a couple of things to it. I'm trying to make a javascript file with a list of pictures in it for a website. I need to get to relative location of the pictures and put parentheses around the names and a comma after each name.
sample of what's needed, var imgList = [ "pic/1.gif", "pic/2.jpg", "pic/3.jpg", "4.jpg", "5.jpg", "6.jpg" ];
using this
echo var imgList = [ > "imglist.js" dir /A:-D /s /b >> "imglist.js" echo ]; >> "imglist.js"
I just need a way to get the dir command to only search in folders "below" where it is run. So I would run the batch file from images and it would return what the first list has. Also as noted before parentheses have to be added and a comma.
Is this easily possible? I have been trying to modify something i had from another project to get what I need but I couldn't get it to work.
Thanks this does create the properly formated list I need. There is only one thing missing. Is there an easy way to have this search the folders below where the batch file is run from instead of the folder it is in.
All I need now is to be able to search multiple subdirectories. So if I run it in d:\pics it will search all of the subdirectories in d:\pics
Thanks Mechanix2Go, it makes the list nicely. I just threw in the directory i needed in the first for loop and put parenthesis and a comma on the file name.
This is what I did
setLocal EnableDelayedExpansion
set WD=%CD%
echo var imgList = [ > %WD%\imglist.js
for /f "tokens=* delims= " %%d in ('dir "E:\pics\1280 up" /s/b/ad') do ( pushd "%%d"
for /f "tokens=* delims= " %%f in ('dir/b/a-d 2^> nul') do ( echo "%%f", >> %WD%\imglist.js
) )
echo ]; >> %WD%\imglist.js
I played with this script for a while and only have one more question. I would the like the name of the folder then the picture name.
If i stick %%d\ infront of the %%f I get what is above. Is there way to remove the E:\pics\1280 up\ or a different way to get just the folder the picture is in?
tonysathre I do not want the full path to the picture just the name of the folder the picture is in.
Is there a way to find and replace, so I could replace E:\pics\1280 up with nothing. This would leave only the folder then the pictures that are in the folder
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE