只是想知道.NET是否提供了一种干净的方法来执行此操作:
int64 x = 1000000;
string y = null;
if (x / 1024 == 0) {
y = x + " bytes";
}
else if (x / (1024 * 1024) == 0) {
y = string.Format("{0:n1} KB", x / 1024f);
}
Run Code Online (Sandbox Code Playgroud)
等等...
var length = new System.IO.FileInfo(path).Length;
Run Code Online (Sandbox Code Playgroud)
这给出了文件的逻辑大小,而不是磁盘上的大小.
我想在C#中获取磁盘上文件的大小(最好没有互操作),如Windows资源管理器所报告的那样.
它应该给出正确的大小,包括:
今天我注意到我制作的一个小程序经常在程序生命周期的前10~20秒内触发GC.之后它再也几乎没有触发.

在这段时间内只运行一个函数,即下面的函数.获取~2k的文件路径,并过滤掉大部分文件路径.
public static string[] FilterFiles(string path)
{
// Fetch the files from given directory
var files = Directory.GetFiles(path);
// Delete all files that are to small
foreach (string file in files)
{
string fullFile = default(string);
try
{
fullFile = File.ReadAllText(file);
}
catch
{
continue;
}
if (fullFile.Length < Settings.MinimumFileSize)
{
File.Delete(file);
}
}
// Obtain the new list without the small files
List<string> cleanFiles = new List<string>(Directory.GetFiles(path));
List<string> cleanReturn = new List<string>(Directory.GetFiles(path));
// Remove files we have handled …Run Code Online (Sandbox Code Playgroud) 我已经开发了一个SSIS包来在特定的位置创建ZIP文件.我能够发送ZIP文件的电子邮件附件.现在,我想做以下事情:
如果我的文件大小小于1MB,则发送带附件的电子邮件; 否则,只发送电子邮件通知(没有附件).我也想让它也可以配置.
所以,我想知道,SSIS中是否有任何方法来检查文件大小并采取必要的措施?