Page 1 of 1

Batch file needed to sort alpha channel tga files.

Posted: 11 Nov 2014 13:41
by val5662
Hi All........ :D
I need a batch file to sort tga image files.
I have Win 7 pro 64 bit.
I have a bunch of tga image files.Some have alpha channels.What I want to do is find a hex string 08 ( zero eight ) and use "goto movethem" as shown in the examples below.There is only one 08 hex string in each of my tga files that have an alpha channel.
The 2 examples below won't work.The first one moves the ones with no alpha channel also.The 2nd one just makes the folder,does nothing else.
Please help.Thanks!
Val

@echo off
md alpha-tgas
findstr /I "08" *.tga
if exist goto movethem
:movethem
move *.tga alpha-tgas
pause
exit /b

@echo off
md alpha-tgas
for /f "eol=: delims=" %%F in ('findstr /m 08 *.tga') do @move "%%F" alpha-tgas >nul
pause
exit /b

Re: Batch file needed to sort alpha channel tga files.

Posted: 12 Nov 2014 03:37
by foxidrive
.TGA is a binary image file of a bunch of megabytes right? Can you be certain that 08 is an illegal sequence in a .TGA file?

Re: Batch file needed to sort alpha channel tga files.

Posted: 12 Nov 2014 11:03
by val5662
foxidrive....
Here is a link to a hex image of one of the alpha channel tga files.
Hope that helps.
http://vnovak.com/has1alphachannel.html
Thanks!

Re: Batch file needed to sort alpha channel tga files.

Posted: 12 Nov 2014 23:18
by foxidrive
val5662 wrote:foxidrive....
Here is a link to a hex image of one of the alpha channel tga files.
Hope that helps.
http://vnovak.com/has1alphachannel.html
Thanks!


This is a binary file of image data right? http://en.wikipedia.org/wiki/Truevision_TGA

I didn't look closely but I've never seen an image format that doesn't allow any of the entire range of hex values,
and your image only shows a kb or so so I can't tell what other data is in the file.

You're saying that the hex value 08 doesn't exist in any of the image data, only in the header of an alpha channel image
(and I admit that am not familiar with alpha channel image data)

If that is the case then try this:

Code: Select all

@echo off
md "alpha-tgas" 2>nul
:: Define BS to contain a backspace
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
for %%a in (*.tga) do findstr /I "%BS%" "%%a" >nul && move "%%a" "alpha-tgas" >nul
pause

Re: Batch file needed to sort alpha channel tga files.

Posted: 13 Nov 2014 07:06
by val5662
foxidrive.........
Thanks a lot !
Your code:

Code: Select all

@echo off
md "alpha-tgas" 2>nul
:: Define BS to contain a backspace
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
for %%a in (*.tga) do findstr /I "%BS%" "%%a" >nul && move "%%a" "alpha-tgas" >nul
pause


worked 100% by moving all the alpha channel tgas and leaving the tga files with no alpha channel alone as those do not have a "08" anywhere.

If you have time , could you explain the basics of how your code worked?
How did the code know to search for "08" ?
What does BS stand for ?
( just a very short explanation is ok )

Thanks again!
I appreciate your help a bunch !
Val

MOD EDIT: PLEASE USE CODE TAGS

Re: Batch file needed to sort alpha channel tga files.

Posted: 13 Nov 2014 10:54
by ShadowThief
val5662 wrote:foxidrive.........
Thanks a lot !
Your code:

Code: Select all

@echo off
md "alpha-tgas" 2>nul
:: Define BS to contain a backspace
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
for %%a in (*.tga) do findstr /I "%BS%" "%%a" >nul && move "%%a" "alpha-tgas" >nul
pause


worked 100% by moving all the alpha channel tgas and leaving the tga files with no alpha channel alone as those do not have a "08" anywhere.

If you have time , could you explain the basics of how your code worked?
How did the code know to search for "08" ?
What does BS stand for ?
( just a very short explanation is ok )

Thanks again!
I appreciate your help a bunch !
Val

BS is just what he named the variable. He could have called it anything, really; he just went with BS (short for backspace).

This code takes advantage of the fact that the ASCII value of the backspace character is 08. It then searches the TGA file for the backspace character and if it is found, it moves that file to the alpha-tgas directory.

Re: Batch file needed to sort alpha channel tga files.

Posted: 13 Nov 2014 12:11
by Squashman
ShadowThief wrote:BS is just what he named the variable. He could have called it anything, really; he just went with BS (short for backspace).
.

And I thought he was making a Cow Dung reference. :lol:

Re: Batch file needed to sort alpha channel tga files.

Posted: 13 Nov 2014 22:38
by val5662
Thanks all ! :D
Call this problem solved.
echo Topic closed :D
Val

Re: Batch file needed to sort alpha channel tga files.

Posted: 15 Nov 2014 10:13
by Samir
val5662 wrote:Thanks all ! :D
Call this problem solved.
echo Topic closed :D
Val
You can't

Code: Select all

call this problem solved

or you'll get a

Code: Select all

file not found
:lol:

Sorry, bad batch joke. :P

Glad these guys were able to help you. Your use case is why batch files are so awesome. The execution was probably lightning fast too!