檔案獲取基本資訊

2022-02-25 09:51:37 字數 1910 閱讀 4124

獲取檔案的基本資訊科通過system.io 命名空間下的

fileinfo

類來實現

lfileinfo類的許多方法與

file

類中的對應方法類似,大多數情況並不重要,但下面的規則有助於確定那種技術更合適;

l如果僅進行單一方法呼叫,則可以使用靜態file類上的方法,在此,單一呼叫要更快一些,因為

.netframework

不必例項化新物件,在呼叫方法。

l如果應用程式在檔案上執行幾種操作,則例項化fileinfo物件並使用其方法就更好一些。這節省時間,因為物件已在檔案系統上引用正確的檔案,而靜態類必須每次都尋找類。

lfileinfo 類也提供了與底層檔案相關的屬性,其中一些屬性可以用來更新檔案,其中很多屬性都繼承與

filesysteminfo

,所以可應用於

fileinfo

和directoryinfo

類。

filesysteminfo類的屬性

exists確定人間是否存在,是唯讀抽象屬性

attributes獲取或設定當前檔案或目錄的特性

extension提取檔案的副檔名,此屬性唯讀

fullname檢索檔案的完整路徑,唯讀屬性

name檢索檔案的完成路徑,唯讀抽象屬性

lastaccrsstime(

utc)獲取或設定上次訪問當前檔案

日期和時間,可以使用utc或非

utc版本

lastwritetime(

utc) 獲取或設定上次訪問當前檔案日期和時間,可以使用

utc或非

utc

creationtime(utc) 獲取當前檔案的建立日期和時間,可以使用

utc或非

utc

directory包含當前檔案目錄,唯讀屬性

directoryname返回檔案的路徑,唯讀屬性

isreadonly唯讀特性的快捷方式,也可以通過attribues來訪問這個屬性

length獲取檔案的大小(以位元組為單位),返回long值,唯讀屬性

string path = @"

c:\users\administrator\desktop\51zxw.txt";

fileinfo mypath = new

fileinfo(path);

if(mypath.exists)

else

console.read();

}

檔案基本操作之獲取檔案基本資訊

學習關於檔案的 1.獲取檔案的開啟路徑。2.獲取副檔名 3.獲取檔案的建立時間 4.獲取最後修改檔案的時間 5.向richtextbox新增文字 先看下大概介面功能 部分 獲取檔案路徑 private void btngetfile click object sender,eventargs e 獲...

Go 獲取檔案基本資訊方法

最近一直在寫 go 語言,總結下go獲取檔案資訊的方法 fileinfo,os.stat test.log 修改時間 modtime fileinfo.modtime fmt.println modtime err os.stat test.log if os.isnotexist err file...

獲取手機基本資訊

獲取手機基本資訊 telephonymanager tm telephonymanager context.getsystemservice context.telephony service 注意在androidmanifest中新增許可權 string mobile tm.getline1num...