我目前正在尝试检查文件大小,如果它是0Kb做xxxx,否则做yyyyyyyyyyy
我目前只有批量替代方案:
FOR /F "usebackq" %%A IN ('%file%') DO set size=%%~zA
if %size% LSS %maxbytesize% (
TIMEOUT /T 1
) ELSE (
start "" "alert.bat"
)
有人可以在C#中证明这一点吗
答案 0 :(得分:9)
FileInfo file = new FileInfo("myfile.dat");
if (file.Length > 0)
{
// do xxx
}
else
{
// do yyyyyyyyyy
}
答案 1 :(得分:2)
FileInfo info = new FileInfo("somefile");
if( info.Length > 0 )
{
// Do something
}
else
{
// Do something else
}
答案 2 :(得分:0)
希望这个可以帮助你!
using System;
using System.IO;
class Program {
static void Main() {
// The name of the file
const string fileName = "test.txt";
// Create new FileInfo object and get the Length.
FileInfo f = new FileInfo(fileName);
long size = f.Length;
if(size == 0) {
/* do something */
} else {
/* do something */
}
}
}
答案 3 :(得分:0)
FileStream file = File.Open("C:\\Users\\bkrupa\\Desktop\\new.txt", FileMode.Open);
if (file.Length == 0)
{
Console.WriteLine("Empty");
}
Console.Read();