我想检查压缩文件中的文件是否为空。我知道该unzip -l命令,但它提供了很多信息。
[abc@localhost test]$ unzip -l empty_file_test.zip
Archive: empty_file_test.zip
Length Date Time Name
--------- ---------- ----- ----
0 07-05-2017 06:43 empty_first_20170505.csv
0 07-05-2017 06:43 empty_second_20170505.csv
--------- -------
0 2 files
Run Code Online (Sandbox Code Playgroud)
我通过命令从zip文件中提取了文件名
file_names="$(unzip -Z1 empty_file_test.zip)
file_name_array=($file_names)
file1=${file_name_array[0]}
file2=${file_name_array[1]}
Run Code Online (Sandbox Code Playgroud)
我尝试使用-s选项,但没有用
if [ -s $file1 ]; then
echo "file is non zero"
else
echo "file is empty"
fi
Run Code Online (Sandbox Code Playgroud)
file is empty即使文件不为空,也始终打印。
我使用的是 Visual C++ 2008。在 VC++ 2008 中,CFile支持 2^64 个大文件。所以我觉得CStdioFile也应该支持。
但是,当CStdioFile::GetLength()在大于 2GB 的文件上使用时,我得到一个CFileException,下面是代码片段:
void CTestCStdioFileDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
CStdioFile MyFile;
CString strLine;
ULONGLONG uLength;
strLine = _T("This is a line.");
if (MyFile.Open(_T("C:\\Temp\\MyTest.dat"), CFile::modeCreate | CFile::modeWrite | CFile::shareExclusive | CFile::typeBinary))
{
for (UINT uIndex = 0; uIndex = 200000000; uIndex ++)
{
MyFile.WriteString(strLine);
uLength = MyFile.GetLength();
}
MyFile.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
跟踪到 后CStdio::GetLength(),我发现以下代码片段将引发异常,如下所示:
nCurrent = ftell(m_pStream); …Run Code Online (Sandbox Code Playgroud)