C 操作檔案以及資料夾

2021-05-23 21:12:31 字數 2027 閱讀 3953

class program

;fs.write(info, 0, info.length);

fs.close();}}

catch(exception ee)

}/**

/// copy檔案

/// 支援copy後重新命名

///

public static void copyfile()

if(file.exists(objectpath))//目標檔案

file.copy(sourcepath,objectpath);//這裡的引數是兩個檔案路徑,目標檔名可以不同於源檔名,效果是把原始檔copy到新的路徑,並且重新命名

}catch(exception ee)

}/**

/// 移動檔案

/// 支援移動後重新命名

///

public static void movefile()

if(file.exists(objectpath))//目標檔案

file.move(sourcepath,objectpath);//這裡的引數是兩個檔案路徑,目標檔名可以不同於源檔名,效果是把原始檔移動到新的路徑,並且重新命名

}catch(exception ee){}}

/**

/// 刪除檔案

///

public static void deletefile()

file.delete(path);

}catch(exception ee){}}

/**

/// 獲取檔案資訊

///

static string filename = "";

static string filelength = "";

static string filetime = "";

static string fileattributes = "";

public static void fileinfo()

filename = fi.directoryname;//檔案完整路徑

filelength = fi.length.tostring();//檔案長度

filetime = fi.creationtime.tostring();//檔案建立的時間

fileattributes = fi.attributes.tostring();//屬性,指得是右擊檔案-->屬性-->常規下的高階-->存檔和編制索引屬性下的 可以存檔檔案選項

//還有很多屬性,用法差不多

}catch(exception ee){}}

//以下是操作資料夾**************************************

/**

/// 追加資料夾,不存在則建立

///

///

///

public static string createdirectory1(string path)

directoryinfo dirinfo = directory.createdirectory(path);//用於建立指定目錄的資料夾

return "路徑建立成功!";

}catch (exception ee)

}/**

/// 移動資料夾

/// 支援重新命名

///

public static void movedirectory()

if (directory.exists(objectpath))

directory.move(sourcepath,objectpath);

}catch(exception ee){}}

/**

/// 刪除資料夾

///

public static void deletedirectory()

directory.delete(path);

}catch(exception ee){}}

static void main(string args)}

nodejs 操作檔案(資料夾)

1.建立資料夾 if fs.existssync targetdir 2.刪除資料夾 方法1 使用遞迴 var deletefolderrecursive function path else fs.rmdirsync path 方法2 使用系統的命令 var exec require child ...

liunx操作資料夾

cd命令是linux中最常用的命令之一,它用於切換目錄 命令功能 cd 切換到主目錄 cd 切換到上乙個工作目錄 cd 返回上兩級目錄 cd 當前目錄 cd 返回上級目錄 pwd檢視當前在哪個目錄 ls命令用來列出目錄下的檔案 命令功能 ls a 列出檔案下所有的檔案,包括以 開頭的隱藏檔案 ls ...

php操作資料夾

對檔案內容操作 readfile a.txt 讀取文字內容 var dump file a.txt 索引陣列對每一行排序 str file get contents a.txt 把檔案內容原樣輸出相當於python的 var dump str file put contents tst.txt 這是...