本文整理汇总了C#中DirectoryInfo类的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo类的具体用法?C# DirectoryInfo怎么用?C# DirectoryInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DirectoryInfo类属于命名空间,在下文中一共展示了DirectoryInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DirectoryCopy
private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
{
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
DirectoryInfo[] dirs = dir.GetDirectories();
if (!dir.Exists)
{
throw new DirectoryNotFoundException(
"Source directory does not exist or could not be found: "
+ sourceDirName);
}
if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
string temppath = Path.Combine(destDirName, file.Name);
file.CopyTo(temppath, true);
}
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
string temppath = Path.Combine(destDirName, subdir.Name);
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
}
}
}
示例2: CopyAll
/// <summary>
/// Recursive Copy Directory Method
/// </summary>
private static void CopyAll(DirectoryInfo source, DirectoryInfo target)
{
// Check if the source directory exists, if not, don't do any work.
if (!Directory.Exists(source.FullName))
{
return;
}
// Check if the target directory exists, if not, create it.
if (!Directory.Exists(target.FullName))
{
Directory.CreateDirectory(target.FullName);
}
// Copy each file into it’s new directory.
foreach (var fileInfo in source.GetFiles())
{
fileInfo.CopyTo (Path.Combine (target.ToString (), fileInfo.Name), true);
}
// Copy each subdirectory using recursion.
foreach (var subDirInfo in source.GetDirectories())
{
DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(subDirInfo.Name);
CopyAll(subDirInfo, nextTargetSubDir);
}
}
示例3: renameFile
public static void renameFile(DirectoryInfo directory, FileInfo[] files, int i, string nameNumber)
{
Console.WriteLine(directory.Name);
string newName = [email protected]"\"+directory.Name + "-" + nameNumber+((FileInfo)files[i]).Extension;
Console.WriteLine(newName);
File.Move(((FileInfo)files[i]).FullName, newName);
}
示例4: destroyOldExcel
/// <summary>
/// Destory Old Excel
/// </summary>
private void destroyOldExcel()
{
try
{
string path = Server.MapPath("~") + @"ExcelReport\";
string folderName = DateTime.Now.ToString("yyyyMMdd");
DirectoryInfo root = new DirectoryInfo(path);
DirectoryInfo[] nodes = root.GetDirectories();
FileInfo[] files = null;
for (int i = 0; i < nodes.Length; i++)
{
if (!string.Equals(nodes[i].Name, folderName))
{
files = nodes[i].GetFiles();
for (int j = 0; j < files.Length; j++)
{
if (files[j].Attributes.ToString().IndexOf("ReadOnly") != -1)
{
files[j].Attributes = FileAttributes.Normal;
}
files[j].Delete();
}
nodes[i].Delete();
}
}
}
catch { }
}
示例5: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["LoginStatus"] == null)
{
Response.Redirect("Signin.aspx");
}
}
StringBuilder sb = new StringBuilder();
sb.AppendLine("<table class=\"table table-hover\">");
sb.AppendLine("<tr><th width=\"50%\">文件名</th><th width=\"20%\">大小</th><th width=\"20%\">修改日期</th><th></th></tr>");
DirectoryInfo directoryInfo = new DirectoryInfo(pptpath);
foreach (FileInfo fileinfo in directoryInfo.GetFiles())
{
sb.AppendLine("<tr><td><a href=\"./file/ppt/" + fileinfo.Name + "\">" + fileinfo.Name + "</a></td><td>" + fileinfo.Length / 1024 + " KB</td><td>" + fileinfo.LastAccessTime + "</td><td><a class=\"btn btn-small btn-primary\" href=\"./file/ppt/" + fileinfo.Name + "\">下载</a>");
if (Session["LoginId"].ToString() == "246246" || Session["LoginId"].ToString() == "91225")
{
sb.AppendLine("<a class=\"btn btn-danger btn-small\" href=\"DeleteFile.aspx?type=ppt&filename=" + fileinfo.Name + "\">删除</a>");
}
sb.AppendLine("</td></tr>");
}
sb.AppendLine("<tr><td colspan=\"4\"><a class=\"btn btn-info btn-small\" href=\"AddFile.aspx?type=ppt\">添加</a></td></tr>");
sb.AppendLine("</table>");
this.pptTable = sb.ToString();
}
示例6: AssetsConvertLineEndings
public static void AssetsConvertLineEndings()
{
try
{
DirectoryInfo projectDir = new DirectoryInfo(Directory.GetCurrentDirectory());
if (null == projectDir)
{
return;
}
foreach (DirectoryInfo subDir in projectDir.GetDirectories())
{
if (null == subDir)
{
continue;
}
if (subDir.Name.ToUpper().Equals("ASSETS"))
{
AssetsConvertLineEndings(subDir);
}
}
}
catch (System.Exception ex)
{
Debug.LogError(string.Format("Exception={0}", ex));
}
AssetDatabase.Refresh();
Debug.Log(string.Format("{0} Processing is done", DateTime.Now));
}
示例7: Folder
public Folder(string path)
{
DirectoryInfo dirInfo = new DirectoryInfo(path);
this.Name = dirInfo.Name;
CreateRecursivelyFilesAndFolders(dirInfo);
}
示例8: getMapsInfo
void getMapsInfo()
{
DirectoryInfo dir = new DirectoryInfo(Application.dataPath+"/Maps/");
FileInfo[] info = dir.GetFiles("*.*");
foreach (FileInfo f in info)
{
if(f.FullName.EndsWith("meta"))
{
continue;
}
if(f.FullName.EndsWith("jpg"))
{
Texture2D tex = (Texture2D) Resources.Load(f.Name);
thumbnails.Add(tex);
Debug.Log ("Thumbnail "+ f.Name + " added!");
continue;
}
lvlNames.Add(f.Name.Replace(".save",""));
Debug.Log (f.Name.Replace(".save",""));
}
//lvl1text.text = lvlNames [1];
//lvl2text.text = lvlNames [2];
}
示例9: folderIsPngFolder
/// <summary>
/// Check wether or not the folder is a png folder
/// </summary>
/// <returns></returns>
private bool folderIsPngFolder()
{
DirectoryInfo dir = new DirectoryInfo(this.dicomPath);
FileInfo[] info = dir.GetFiles("*.png*");
return info.Length > 2;
}
示例10: Returned304
/// <summary>
/// Returns 304 (use cached version) code to the client if
/// file was not changed since last request.
/// </summary>
/// <param name="fileInfo">File location information</param>
/// <returns>True if 304 was returned.</returns>
public static bool Returned304(DirectoryInfo dirInfo)
{
if (!dirInfo.Exists)
return false;
return Returned304(dirInfo.LastWriteTime);
}
示例11: GetAssets
public static void GetAssets(string extension, Dictionary<string, string> files, DirectoryInfo directory)
{
if (null == directory)
{
return;
}
foreach (FileInfo file in directory.GetFiles(extension))
{
if (string.IsNullOrEmpty(file.FullName) ||
files.ContainsKey(file.FullName.ToLower()))
{
continue;
}
files.Add(file.FullName.ToLower(), file.FullName);
}
foreach (DirectoryInfo subDir in directory.GetDirectories())
{
if (null == subDir)
{
continue;
}
if (subDir.Name.ToUpper().Equals(".SVN"))
{
continue;
}
//Debug.Log(string.Format("Directory: {0}", subDir));
GetAssets(extension, files, subDir);
}
}
示例12: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
DirectoryInfo dir = new DirectoryInfo(MapPath("~/Upload images/"));
FileInfo[] file = dir.GetFiles();
ArrayList list = new ArrayList();
ArrayList listvid = new ArrayList();
ArrayList listaud = new ArrayList();
foreach (FileInfo file2 in file)
{
if (file2.Extension == ".jpg" || file2.Extension == ".jpeg" || file2.Extension == ".gif" || file2.Extension == ".png")
{
list.Add(file2);
}
if (file2.Extension == ".mp4")
{
listvid.Add(file2);
}
if (file2.Extension == ".mp3")
{
listaud.Add(file2);
}
}
DataList3.DataSource = listaud;
DataList3.DataBind();
DataList1.DataSource = list;
DataList1.DataBind();
DataList2.DataSource = listvid;
DataList2.DataBind();
}
示例13: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
DirectoryInfo dir = new DirectoryInfo(MapPath("~/Health_new/p_typhoid"));
FileInfo[] file = dir.GetFiles();
ArrayList list = new ArrayList();
foreach (FileInfo file2 in file)
{
if (file2.Extension == ".mp3")
{
list.Add(file2);
}
}
DataList1.DataSource = list;
DataList1.DataBind();
dir = new DirectoryInfo(MapPath("~/Health_new/d_typhoid"));
file = dir.GetFiles();
list = new ArrayList();
foreach (FileInfo file2 in file)
{
if (file2.Extension == ".mp3")
{
list.Add(file2);
}
}
DataList2.DataSource = list;
DataList2.DataBind();
}
示例14: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["LoginStatus"] == null)
{
Response.Redirect("Signin.aspx");
}
if (Session["LoginId"].ToString() == "246246" || Session["LoginId"].ToString() == "91225")
{
update = "<a class=\"btn btn-info\" href=\"updateSimulatorApp.aspx\">更新</a>";
}
}
this.DownloadUrl = "./file/Simulator/" + System.Configuration.ConfigurationManager.AppSettings["SimulatorFileName"];
this.ManualUrl = "./file/Simulator/" + System.Configuration.ConfigurationManager.AppSettings["SimulatorManualName"];
this.Version = System.Configuration.ConfigurationManager.AppSettings["SimulatorVersion"];
DirectoryInfo directoryInfo = new DirectoryInfo(System.Configuration.ConfigurationManager.AppSettings["SimulatorLocalPath"]);
foreach (FileInfo fileinfo in directoryInfo.GetFiles())
{
if (fileinfo.Name == ConfigurationManager.AppSettings["SimulatorFileName"])
{
this.UpdateTime = fileinfo.LastWriteTime.ToString();
}
}
}
示例15: Start
// Use this for initialization
void Start()
{
controller.GetComponent<BoxCollider> ().enabled = false;
DirectoryInfo dirInfo = new DirectoryInfo("Assets/Resources/Songs");
FileInfo[] files = dirInfo.GetFiles();
int index = -2;
foreach (FileInfo fileInfo in files) {
if (fileInfo.Extension != ".meta") {
string name = fileInfo.Name.Split('.')[0];
GameObject button = Instantiate(buttonPrefab) as GameObject;
button.transform.FindChild("Text").GetComponent<UnityEngine.UI.Text>().text = name;
button.GetComponent<ButtonClicked>().name = name;
button.transform.SetParent(songList.transform);
Vector3 pos = buttonPrefab.transform.localPosition;
pos.y += index++ * WIDTH_GAP;
button.transform.localPosition = pos;
button.transform.localRotation = buttonPrefab.transform.localRotation;
button.transform.localScale = buttonPrefab.transform.localScale;
}
}
transform.Find("Score").GetComponent<UnityEngine.UI.Text>().text =
"Score:" + Player.mScore;
transform.Find("Combo").GetComponent<UnityEngine.UI.Text>().text =
"Combo:" + Player.mCombo;
}