当前位置:网站首页>Judge whether the network file exists, obtain the network file size, creation time and modification time
Judge whether the network file exists, obtain the network file size, creation time and modification time
2022-06-12 11:38:00 【scimence】
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
namespace Sci
{
/// <summary>
/// Network file processing tool
/// </summary>
class WebFile
{
/// <summary>
/// Determine whether the network file exists
/// </summary>
/// <param name="url"></param>
public static bool fileExist(string url)
{
return getFileLen(url) != -1;
}
/// <summary>
/// Get network file size
/// </summary>
/// <param name="url"> Website of the document </param>
/// <returns></returns>
public static long getFileLen(string url)
{
try
{
WebRequest request = WebRequest.Create(url);
request.Timeout = 200;
WebResponse response = request.GetResponse();
return response.ContentLength; // file size
//return response.ContentType; // file type
}
catch (Exception)
{
return -1; // file does not exist
}
}
/// [Accept-Ranges, bytes]
/// [Content-Length, 13927]
/// [Content-Type, application/x-zip-compressed]
/// [Date, 2022-05-28 12:32:59]
/// [ETag, "9258b93b05ed81:0"]
/// [Last-Modified, 2022-05-02 16:40:10]
/// [Server, Microsoft-IIS/8.5]
/// [X-Powered-By, ASP.NET]
/// <summary>
/// Get network file attribute information , Such as :getFileInfo(url)["Last-Modified"];
/// </summary>
/// <param name="url"> Website of the document </param>
/// <returns></returns>
public static Dictionary<string, string> getFileInfo(string url)
{
Dictionary<string, string> dic = new Dictionary<string, string>();
try
{
WebRequest request = WebRequest.Create(url);
request.Timeout = 200;
WebResponse response = request.GetResponse();
WebHeaderCollection col = response.Headers;
foreach (string key in col.Keys)
{
string value = col.Get(key);
if (value.EndsWith(" GMT")) value = DateTime.Parse(value).ToString("yyyy-MM-dd HH:mm:ss");
if (!dic.ContainsKey(key)) dic.Add(key, value);
}
}
catch (Exception)
{
}
return dic;
}
}
}
边栏推荐
猜你喜欢

Doris记录服务接口调用情况

Deep learning and CV tutorial (14) | image segmentation (FCN, segnet, u-net, pspnet, deeplab, refinenet)

字节序 - 如何判断大端小端

人类想要拥有金钱、权力、美丽、永生、幸福……但海龟只想做一只海龟

^33 variable promotion and function promotion interview questions

conda环境下pip install 无法安装到指定conda环境中(conda环境的默认pip安装位置)

C# 37. textbox滚动条与多行

Lambda and filter, List 和 numpy array的索引,以及各种距离指标distance-metrics,拼接数组以及axis=0 and axis=1的区分

logrotate日志轮转方式create和copytruncate原理

6.6 Convolution de séparation
随机推荐
AcWing 1921. Rearranging cows (ring diagram)
logrotate日志轮转方式create和copytruncate原理
Lambda and filter, List 和 numpy array的索引,以及各种距离指标distance-metrics,拼接数组以及axis=0 and axis=1的区分
Clickhouse column basic data type description
tensorflow 2. X multi classification confusion matrix and evaluation index calculation method (accuracy rate, recall rate, F1 score)
Unlimited growth, we will all go to the future | the 15th anniversary of the founding of InfoQ China
21 reasons why you need social media QR code
Redis summary
UI自动化测试中比较少见的异常记录
判断网络文件是否存在,获取网络文件大小,创建时间、修改时间
Unity 连接 Microsoft SQLSERVER 数据库
go基于阿里云实现发送短信
7-5 复数四则运算
6.6 separate convolution
The evil 203 in systemctl
UML series articles (30) architecture modeling -- product diagram
Golang Foundation (6)
Design of TTable
Manuscript manuscript format preparation
Using stairs function in MATLAB