如何知道文件是否为二进制

时间:2019-05-10 18:21:48

标签: file smalltalk gnu-smalltalk

我知道我可以获取目录中所有文件的列表并使用代码打印它们的名称:

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

我可以使用isDirectory来确定文件是否为目录。

如何确定文件是二进制文件而不是文本文件。

isBinary被提及here,但它不起作用:

(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)

如何确定文件是否为二进制文件?

0 个答案:

没有答案