当前位置: 首页>>代码示例>>C#>>正文


C# DirectoryInfo类代码示例

本文整理汇总了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);
			}
		}
	}
开发者ID:Charkova,项目名称:MetaEden.a14,代码行数:33,代码来源:CoherentPostProcessor.cs

示例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);
        }
    }
开发者ID:Fertogo,项目名称:Rox-Star,代码行数:30,代码来源:KinectCopyPluginDataHelper.cs

示例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);
 }
开发者ID:JonathanGiovanny,项目名称:codingground,代码行数:7,代码来源:main.cs

示例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 { }
 }
开发者ID:gracianani,项目名称:SINO_CRM,代码行数:31,代码来源:SiemensCRMEnter.aspx.cs

示例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();
    }
开发者ID:ceie246,项目名称:MIPS246_Software,代码行数:30,代码来源:ppt.aspx.cs

示例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));
    }
开发者ID:robinpan,项目名称:bear_minimum,代码行数:29,代码来源:MenuAssetsConvertToDosLineEndings.cs

示例7: Folder

    public Folder(string path)
    {
        DirectoryInfo dirInfo = new DirectoryInfo(path);
            this.Name = dirInfo.Name;

            CreateRecursivelyFilesAndFolders(dirInfo);
    }
开发者ID:stoyanovalexander,项目名称:TheRepositoryOfAlexanderStoyanov,代码行数:7,代码来源:Folder.cs

示例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];

		

	}
开发者ID:thedodo,项目名称:JumpManClean,代码行数:29,代码来源:LevelManager.cs

示例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;
    }
开发者ID:SuperValou,项目名称:VirtualScanner,代码行数:11,代码来源:DicomPngConvertor.cs

示例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);
    }
开发者ID:Dashboard-X,项目名称:MP3-MusicPlayer-Install-Configure,代码行数:13,代码来源:UtilityMethods.cs

示例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);
     }
 }
开发者ID:thoniorf,项目名称:ouya-sdk-examples,代码行数:29,代码来源:OuyaMenuAdmin.cs

示例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();
    }
开发者ID:jeevan19973,项目名称:ictd4-unnayan,代码行数:33,代码来源:showuploadimages.aspx.cs

示例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();
    }
开发者ID:jeevan19973,项目名称:ictd4-unnayan,代码行数:28,代码来源:Typhoid.aspx.cs

示例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();
            }
        }
    }
开发者ID:ceie246,项目名称:MIPS246_Software,代码行数:28,代码来源:SimulatorApp.aspx.cs

示例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;
    }
开发者ID:youdiaozi,项目名称:AudioSword,代码行数:28,代码来源:Menu.cs


注:本文中的DirectoryInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。