Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

User error with low level file* commands

Hi,

I am not gettign the correct output fro mthe following snippet:

========================================================set fn=C:\Charles_Docs\00035212.jpg
set fh=%@fileopen[%fn,read,b]
iff %fh == -1 then
echo file could not be opened
else
setdos /x-12456789
:: 1 All alias expansion
:: 2 Nested alias expansion only
:: 3 All variable expansion (includes environment variables, batch file parameters, variable
:: function evaluation, and alias parameters)
:: 4 Nested variable expansion only
:: 5 Multiple commands, conditional commands, and piping (affects the command separator, ||,
:: &&, |, and |&)
:: 6 Redirection (affects < , >, >&, >&>, etc.)
:: 7 Quoting (affects back-quotes [`] and double quotes ["]) and square brackets)
:: 8 Escape character
:: 9 Include lists
set nRes=%@FILESEEK[%fh,0,0]
iff %nRes == -1 then
echo File not Seeked: %nRes
else
set tst=%@fileread[%fh,12]
set nLen=%@len[%tst]
echo Read %nLen bytes....
:: returns "Read 4 bytes" - not 12
set fc=%@fileclose[%fh]
iff %fc == -1 then
echo File not closed...
endiff
endiff
setdos /x0
endiff
unset fn, fh, nRes, tst, fc
========================================================
 
When I tried it on a JPG I have, I got 4 bytes too. It turns out, the first 5
bytes of the JPG are "FFD8FFE000". Perhaps @FILEREAD[] read more than 4 bytes
(don't really know) but I'm pretty sure that @LEN[] will interpret the 0x00 as
the end of a string (thus reporting 4 bytes).

On Tue, 22 Mar 2011 00:12:41 -0400, [email protected] <>
wrote:

|Hi,
|
|I am not gettign the correct output fro mthe following snippet:
|
|========================================================set fn=C:\Charles_Docs\00035212.jpg
|set fh=%@fileopen[%fn,read,b]
|iff %fh == -1 then
| echo file could not be opened
|else
| setdos /x-12456789
| :: 1 All alias expansion
| :: 2 Nested alias expansion only
| :: 3 All variable expansion (includes environment variables, batch file parameters, variable
| :: function evaluation, and alias parameters)
| :: 4 Nested variable expansion only
| :: 5 Multiple commands, conditional commands, and piping (affects the command separator, ||,
| :: &&, |, and |&)
| :: 6 Redirection (affects < , >, >&, >&>, etc.)
| :: 7 Quoting (affects back-quotes [`] and double quotes ["]) and square brackets)
| :: 8 Escape character
| :: 9 Include lists
| set nRes=%@FILESEEK[%fh,0,0]
| iff %nRes == -1 then
| echo File not Seeked: %nRes
| else
| set tst=%@fileread[%fh,12]
| set nLen=%@len[%tst]
| echo Read %nLen bytes....
| :: returns "Read 4 bytes" - not 12
| set fc=%@fileclose[%fh]
| iff %fc == -1 then
| echo File not closed...
| endiff
| endiff
| setdos /x0
|endiff
|unset fn, fh, nRes, tst, fc
|=======================================================
 
Charles I tried you "snippet" with a %1 for FN it worked as I suspected,
What I don't understand is what your trying to achieve
BUT ANYWAY... nRES=%@fileseek[%fh,6,0] FFIND /x would be a better way of
getting the location of the "required text" assuming
you wanted to find "JFIF"

The following script shows the translation error clearly mainly with
PDF's create a temp folder with a bunch binaries and text files.
.zip, .PDF's, .JPG, .dll, .exe, etc.... and plain text .txt files it
shows up quickly something's missing!

cls
setlocal
unset /q *
except (%0) dir /bx . >%@unique[]
set tmp_file=%@EXECSTR[*DIR /A:-D /H /O:-T /F /X /Z]

do r=0 to %@lines[%tmp_file]
set open_%r=%@fileopen[%@line[%tmp_file,%r],r,b]
%@if[%@isprint[%@fileread[%[open_%r],8]] != 0,echo
%@format[-15,Text] %@line[%tmp_file,%r],echo %@format[-15,Binary]
%@line[%tmp_file,%r]]
echo %@fileclose[%[open_%[r]]] >&nul
unset /q open*
enddo
:
del /qk *.tmp
endlocal
quit

changing the read location from 8 to 12 changes the results again!!!!


> -----Original Message-----
> I am not gettign the correct output fro mthe following snippet:
 
[email protected]:
...
| I am not gettign the correct output fro mthe following snippet:
...
| set tst=%@fileread[%fh,12]
| set nLen=%@len[%tst]
| echo Read %nLen bytes....
| :: returns "Read 4 bytes" - not 12

Charles:
I have several alternatives for you.

1/ Use @FILEREADB - it is intended for reading binary files, OR

2/ Use @SAFEREAD in Charles Dye's SafeChars.dll plugin, OR

3/ Use the EXIF utilities to locate and read the fields of interest in the image files. Download is free from www.hugsan.com/EXIFutils/html/features.html, unpaid version has limits of how many fields and files a single invocation can process, but no limit on totals.

All of these will get you closer to your goal.
--
HTH, Steve
 
1/ Use @FILEREADB - it is intended for reading binary files, OR

2/ Use @SAFEREAD in Charles Dye's SafeChars.dll plugin, OR

If it's the null bytes tripping him up, then @FILEREADB is the way to go. SafeChars can't help with that issue; anything which uses null-terminated strings is going to gag on zero bytes.
 
1/ I want to use TCMD 8 - 12.1 - filereadb is not in the help for 8....

2/ prefer not to have to use a plugin....

3/ I have a lot of files with no extensions where my main goal is to write a BTM to examine the files and add the preferred extension. Some will be just text files, HTML files, jpg, gif, whatever "RISS would be if located in the file header, etc...
----- Original Message -----
From: Steve Fabian
To: [email protected]
Sent: Tuesday, March 22, 2011 10:40 AM
Subject: RE: [Support-t-2692] User error with low level file* commands


[email protected]:
...
| I am not gettign the correct output fro mthe following snippet:
...
| set tst=%@fileread[%fh,12]
| set nLen=%@len[%tst]
| echo Read %nLen bytes....
| :: returns "Read 4 bytes" - not 12

Charles:
I have several alternatives for you.

1/ Use @FILEREADB - it is intended for reading binary files, OR

2/ Use @SAFEREAD in Charles Dye's SafeChars.dll plugin, OR

3/ Use the EXIF utilities to locate and read the fields of interest in the image files. Download is free from www.hugsan.com/EXIFutils/html/features.html, unpaid version has limits of how many fields and files a single invocation can process, but no limit on totals.

All of these will get you closer to your goal.
--
HTH, Steve
 
@FILEREAD does not support binary files.
You have to use @FILEREADB which wasn't in v8. Have you tried
using the free TCC/LE ?

-Scott

[email protected] <>
wrote on 03/23/2011 05:06:45 PM:


> [email protected] <>
> 03/23/2011 05:06 PM
>
> Please respond to
>
>
> To
>
> [email protected]
>
> cc
>
> Subject
>
> RE: [Support-t-2692] User error with low level file* commands
>
> 1/ I want to use TCMD 8 - 12.1 - filereadb is not in the help for
8....

>
> 2/ prefer not to have to use a plugin....
>
> 3/ I have a lot of files with no extensions where my main goal is
to

> write a BTM to examine the files and add the preferred extension.


> Some will be just text files, HTML files, jpg, gif, whatever "RISS


> would be if located in the file header, etc...
> ----- Original Message -----
> From: Steve Fabian
> To: [email protected]
> Sent: Tuesday, March 22, 2011 10:40 AM
> Subject: RE: [Support-t-2692] User error with low level file*
commands

>
>
> [email protected]:
> ...
> | I am not gettign the correct output fro mthe following snippet:
> ...
> | set tst=%@fileread[%fh,12]
> | set nLen=%@len[%tst]
> | echo Read %nLen bytes....
> | :: returns "Read 4 bytes" - not 12
>
> Charles:
> I have several alternatives for you.
>
> 1/ Use @FILEREADB - it is intended for reading binary files,
OR

>
> 2/ Use @SAFEREAD in Charles Dye's SafeChars.dll plugin, OR
>
> 3/ Use the EXIF utilities to locate and read the fields of


> interest in the image files. Download is free from www.hugsan.com/
> EXIFutils/html/features.html, unpaid version has limits of how many


> fields and files a single invocation can process, but no limit on
totals.

>
> All of these will get you closer to your goal.
> --
> HTH, Steve
>
>
>
>
 
I guess there is no way to do it in 8? I have all versions to 12.1 of TCMD/TCC
----- Original Message -----
From: samintz
To: [email protected]
Sent: Wednesday, March 23, 2011 05:55 PM
Subject: RE: [Support-t-2692] User error with low level file* commands


@FILEREAD does not support binary files.
You have to use @FILEREADB which wasn't in v8. Have you tried
using the free TCC/LE ?

-Scott

[email protected] <>
wrote on 03/23/2011 05:06:45 PM:



Quote:
> [email protected] <>
> 03/23/2011 05:06 PM
>
> Please respond to
>
>
> To
>
> [email protected]
>
> cc
>
> Subject
>
> RE: [Support-t-2692] User error with low level file* commands
>
> 1/ I want to use TCMD 8 - 12.1 - filereadb is not in the help for

8....


Quote:
>
> 2/ prefer not to have to use a plugin....
>
> 3/ I have a lot of files with no extensions where my main goal is

to


Quote:
> write a BTM to examine the files and add the preferred extension.



Quote:
> Some will be just text files, HTML files, jpg, gif, whatever "RISS



Quote:
> would be if located in the file header, etc...
> ----- Original Message -----
> From: Steve Fabian
> To: [email protected]
> Sent: Tuesday, March 22, 2011 10:40 AM
> Subject: RE: [Support-t-2692] User error with low level file*

commands


Quote:
>
>
> [email protected]:
> ...
> | I am not gettign the correct output fro mthe following snippet:
> ...
> | set tst=%@fileread[%fh,12]
> | set nLen=%@len[%tst]
> | echo Read %nLen bytes....
> | :: returns "Read 4 bytes" - not 12
>
> Charles:
> I have several alternatives for you.
>
> 1/ Use @FILEREADB - it is intended for reading binary files,

OR


Quote:
>
> 2/ Use @SAFEREAD in Charles Dye's SafeChars.dll plugin, OR
>
> 3/ Use the EXIF utilities to locate and read the fields of



Quote:
> interest in the image files. Download is free from www.hugsan.com/
> EXIFutils/html/features.html, unpaid version has limits of how many



Quote:
> fields and files a single invocation can process, but no limit on

totals.


Quote:
>
> All of these will get you closer to your goal.
> --
> HTH, Steve
>
>
>
>
 
---- Original Message ----
From: [email protected]
| 1/ I want to use TCMD 8 - 12.1 - filereadb is not in the help for
| 8....

It is in HELP for V9. You did not indicate what JPsoft command processor version you want to use, nor on what platform. In the absence of the former, and also seeing your name in this NG frequently, I assumed your are using a newer version than V8.

| 2/ prefer not to have to use a plugin....

That's your choice. Regardless, Charles' plugin might not work in V8, anyway.

| 3/ I have a lot of files with no extensions where my main goal is to
| write a BTM to examine the files and add the preferred extension.
| Some will be just text files, HTML files, jpg, gif, whatever "RISS
| would be if located in the file header, etc...

IIRC back in those days I used something like %@ascii[%@fileread[....]]. You may try that. No guarantees!
--
Steve
 

Similar threads

Back
Top