Как узнать, является ли файл двоичным - PullRequest
0 голосов
/ 10 мая 2019

Я знаю, что могу получить список всех файлов в каталоге и напечатать их имена с кодом:

(Directory working: '.') allFilesMatching: '*' 
   do: [:ff| ff name displayNl]

Я могу использовать isDirectory, чтобы узнать, является ли файл каталогом.

Как узнать, является ли файл двоичным, а не текстовым.

isBinary упоминается здесь , но это не работает:

(Directory working: '.') allFilesMatching: '*'
do: [ :ff |
    ((ff name), ': ') display.
    (ff isBinary) ifTrue: ['Binary file' displayNl.]
    ifFalse: [ 'Not a binary file.' displayNl.].
    infile close ].

Ошибка:

$ gst isBinary.st 
"Global garbage collection... done"
/home/abcd/myfile.bin: Object: RecursiveFileWrapper new "<0x7f6decdcdb30>" error: did not understand #isBinary
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
Kernel.RecursiveFileWrapper(Object)>>doesNotUnderstand: #isBinary (SysExcept.st:1448)
optimized [] in UndefinedObject>>executeStatements (isBinary.st:4)
[] in Kernel.RecursiveFileWrapper(FilePath)>>filesMatching:do: (FilePath.st:903)
[] in Kernel.RecursiveFileWrapper>>namesDo:prefixLength: (VFS.st:378)
[] in File>>namesDo: (File.st:589)
BlockClosure>>ensure: (BlkClosure.st:268)
File>>namesDo: (File.st:586)
Kernel.RecursiveFileWrapper>>namesDo:prefixLength: (VFS.st:373)
[] in Kernel.RecursiveFileWrapper>>namesDo:prefixLength: (VFS.st:382)
[] in File>>namesDo: (File.st:589)
BlockClosure>>ensure: (BlkClosure.st:268)
File>>namesDo: (File.st:586)
Kernel.RecursiveFileWrapper>>namesDo:prefixLength: (VFS.st:373)
Kernel.RecursiveFileWrapper>>namesDo: (VFS.st:396)
Kernel.RecursiveFileWrapper(FilePath)>>filesMatching:do: (FilePath.st:902)
File(FilePath)>>allFilesMatching:do: (FilePath.st:775)
Directory class>>allFilesMatching:do: (Directory.st:225)
UndefinedObject>>executeStatements (isBinary.st:1)

Как определитьесли файл является двоичным?

...