Please Help: Passing in list of files in a folder to myVar

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
janimator0
Posts: 2
Joined: 26 Sep 2013 21:18

Please Help: Passing in list of files in a folder to myVar

#1 Post by janimator0 » 26 Sep 2013 21:32

I have a piece of code I wrote for a program called TexturePacker a few months back that magically decided to stop working. I've been trying to solve this problem for a while now with no luck. I hope someone in this forum can help.

I pass in 2 variables to the BatchFile, the name of the directory the files are in and the final output name of the newly created file. The problem is that the file names are 'Bitmap 1.png, Bitmap 2.png, Bitmap 3.png ...', but they're getting read in as '1.png, 2.png, 3.png...'.

Here's the code:

Code: Select all

@echo off

:: takes in the directory of the PNG images to be texture packed
set PathName = %1
set SheetName = %2

:: sets the directory to the path of the PNG images
C:
cd %1

:: creates the variable myvar with the list of PNG images
setlocal enabledelayedexpansion
set myvar=
for /r %%i In (*.png) DO set myvar=!myvar! %%~nxi

:: runs TexturePacker commandline tool
"C:\Program Files (x86)\CodeAndWeb\TexturePacker\bin\TexturePacker.exe" --format json --data texture.json --texture-format png --dpi 72 --opt RGBA8888 --max-size 2048 --sheet %2.png %myvar%

PAUSE


Hopefully this is an easy problem to solve, as it is important for me to fix. Also I very very rarely write batch scripts, so if there's anything odd in my code id appreciate in knowing.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Please Help: Passing in list of files in a folder to myV

#2 Post by foxidrive » 27 Sep 2013 05:25

Spaces in the variable name and in the data should be removed.
These will enable the use of long filenames and & etc.

set "PathName=%~1"
set "SheetName=%~2"

This line also need /d and similar treatment for spaces etc.

cd /d "%~1"

Again, quoting.

for /r %%i In (*.png) DO set myvar=!myvar! "%%~nxi"

Quoting and tilda in the %2 variable. %myvar% is ok as it has quotes applied above.


"C:\Program Files (x86)\CodeAndWeb\TexturePacker\bin\TexturePacker.exe" --format json --data texture.json --texture-format png --dpi 72 --opt RGBA8888 --max-size 2048 --sheet "%~2.png" %myvar%

Try it with those changes and reply - see if the problem has gone away.

janimator0
Posts: 2
Joined: 26 Sep 2013 21:18

Re: Please Help: Passing in list of files in a folder to myV

#3 Post by janimator0 » 27 Sep 2013 08:49

Everything works great now! Thank you very much for the help.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Please Help: Passing in list of files in a folder to myV

#4 Post by foxidrive » 27 Sep 2013 10:47

Great. Thanks for the reply.

Post Reply