标签: file-length

如何检查文件是否为空?

我有一个文本文件.
如何检查它是否为空?

python file file-length

246
推荐指数
7
解决办法
23万
查看次数

如何检查zip文件中文件的长度

我想检查压缩文件中的文件是否为空。我知道该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即使文件不为空,也始终打印。

bash shell zip unzip file-length

1
推荐指数
1
解决办法
81
查看次数

CStdioFile 不能处理大于 2GB 的文件?

我使用的是 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)

c++ mfc ftell visual-c++ file-length

1
推荐指数
1
解决办法
231
查看次数

标签 统计

file-length ×3

bash ×1

c++ ×1

file ×1

ftell ×1

mfc ×1

python ×1

shell ×1

unzip ×1

visual-c++ ×1

zip ×1