AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to distinguish between binary and ascii files?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Fri Apr 15, 2005 12:05 pm    Post subject: How to distinguish between binary and ascii files? Reply with quote

I want my script to treat binary files differently than ASCII files . How can I find out if a file contains binary or ASCII data?
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
BoBo
Guest





PostPosted: Fri Apr 15, 2005 12:37 pm    Post subject: Reply with quote

D'ya wanna transfer (FTP) your files via an AHK script ?
Back to top
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Fri Apr 15, 2005 2:39 pm    Post subject: Reply with quote

No, i want to compress the files differently.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
TeknoMusicMan



Joined: 14 Apr 2005
Posts: 188
Location: Wisconsin, USA

PostPosted: Fri Apr 15, 2005 2:44 pm    Post subject: Reply with quote

try using FileRead to read the file, then check it against a IF statement to see if any of the characters are other then 0 or 1, if not its binary, if it does its ascii.

unless you mean like executables and such, in that case would the .XXX extension be enough to tell you what it is. You could setup a list of binary extensions and a list of ascii extensions and filter them that way.
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Fri Apr 15, 2005 3:50 pm    Post subject: Reply with quote

^ example:
Code:
FileRead, FileVar, FILE.txt
nobin = 2,3,4,5,6,7,8,9,.
if FileVar is integer
   {
   if FileVar not contains %nobin%
      Msgbox Binary file
   else
      Msgbox Not binary file: contains illegal digits
   }
else
   Msgbox Not binary file: contains ASCII (letters)

_________________

Back to top
View user's profile Send private message Visit poster's website
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Fri Apr 15, 2005 3:58 pm    Post subject: Reply with quote

Thanks you all for your comments.

FileRead is not an option, since there are several hundered files with up to 3 GB (!) filesize. So a loop over all files will be too costly.

From all your post I assume the only way to do is to look directly at the contens. So I will try to read 5 or 10 of the first lines (do they exist in binary format?) and guess for the rest.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Fri Apr 15, 2005 4:03 pm    Post subject: Reply with quote

Hmm, reading only a few random lines of a file would be a clever idea. Why couldn't you just take .bin files for binary?
_________________

Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Fri Apr 15, 2005 4:07 pm    Post subject: Reply with quote

If it weren't for the fact that some of your files are so large, the following FileRead idea would probably work. But since they are so large, I think it's impossible to do it directly inside a script. You would probably need an external utility that scans the file for the first binary zero and stops there, reporting the file as binary.

Method that won't help for huge files, but you could use it for ones that pass a smallness filter:
Due to the fact that binary zeroes are used as string terminators in AutoHotkey, if you use FileRead to read in the file and StringLen says the variable's contents are lot shorter than FileGetSize says they should be, that probably means the file is binary.


Last edited by Chris on Fri Apr 15, 2005 4:07 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Fri Apr 15, 2005 4:07 pm    Post subject: Reply with quote

The files I need to process are created by another software that doesn't give extensions to them.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
TeknoMusicMan



Joined: 14 Apr 2005
Posts: 188
Location: Wisconsin, USA

PostPosted: Fri Apr 15, 2005 4:47 pm    Post subject: Reply with quote

Does this software have any sort of naming standard for the files?

what i mean is there any pattern in the filenames or the binary files and non-binary files?

IE: 04152005bin or anything of that nature. If so you could read all the filenames in a directory into an array and read each name to see if it fits the pattern for a bin or non-bin
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
BoBo
Guest





PostPosted: Sat Apr 16, 2005 6:28 am    Post subject: Reply with quote

This might be of help: [file - Dateityp ermitteln] (German). Now you've to check if file is available as an Windows based ---> UnixTool, like [here]

Cool
Back to top
BoBo
Guest





PostPosted: Sun Apr 17, 2005 8:55 pm    Post subject: Reply with quote

If Rabiator is right, as said in [this post] AHK's FileRead could be an option. Smile
Back to top
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Tue Apr 19, 2005 3:14 am    Post subject: Reply with quote

Thanks BoBo,
Chris suggested the same thing 4 posts above yours. :)
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
BoBo
Guest





PostPosted: Tue Apr 19, 2005 6:11 am    Post subject: Reply with quote

I've realized that Chris has mentioned that "workarround" Wink

hm - while Chris pointed out to check for the vars length (StringLen), I've assumed Rabiator's hint is about FileRead's errorlevel. But - who cares Wink
Back to top
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Tue Apr 19, 2005 11:25 am    Post subject: Reply with quote

When I read the manual for FileRead I don't think the Errorlevel will do th etrick, because AHK "thinks" it had read the file successfully when it reaches the first binary 0.
But thanks for pointig that out, I'll look deeper into this soon.

Thank you all, very much appreaciated.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group