Batch file needed to sort alpha channel tga files.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
val5662
Posts: 34
Joined: 18 Dec 2013 09:48

Batch file needed to sort alpha channel tga files.

#1 Post by val5662 » 11 Nov 2014 13:41

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

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

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

#2 Post by foxidrive » 12 Nov 2014 03:37

.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?

val5662
Posts: 34
Joined: 18 Dec 2013 09:48

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

#3 Post by val5662 » 12 Nov 2014 11:03

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!

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

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

#4 Post by foxidrive » 12 Nov 2014 23:18

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

val5662
Posts: 34
Joined: 18 Dec 2013 09:48

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

#5 Post by val5662 » 13 Nov 2014 07:06

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

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

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

#6 Post by ShadowThief » 13 Nov 2014 10:54

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.

Squashman
Expert
Posts: 4487
Joined: 23 Dec 2011 13:59

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

#7 Post by Squashman » 13 Nov 2014 12:11

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:

val5662
Posts: 34
Joined: 18 Dec 2013 09:48

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

#8 Post by val5662 » 13 Nov 2014 22:38

Thanks all ! :D
Call this problem solved.
echo Topic closed :D
Val

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

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

#9 Post by Samir » 15 Nov 2014 10:13

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!

Post Reply