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


C# DirectoryInfo.GetFileSystemInfos方法代码示例

本文整理汇总了C#中DirectoryInfo.GetFileSystemInfos方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.GetFileSystemInfos方法的具体用法?C# DirectoryInfo.GetFileSystemInfos怎么用?C# DirectoryInfo.GetFileSystemInfos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DirectoryInfo的用法示例。


在下文中一共展示了DirectoryInfo.GetFileSystemInfos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CopyDirectory

    /// <summary>
    /// 复制文件夹(及文件夹下所有子文件夹和文件)
    /// </summary>
    /// <param name="sourcePath">待复制的文件夹路径</param>
    /// <param name="destinationPath">目标路径</param>
    public static void CopyDirectory(string sourcePath, string destinationPath)
    {
        DirectoryInfo info = new DirectoryInfo(sourcePath);
        Directory.CreateDirectory(destinationPath);
        foreach (FileSystemInfo fsi in info.GetFileSystemInfos())
        {
            string destName = Path.Combine(destinationPath, fsi.Name);

            if (fsi is System.IO.FileInfo)          //如果是文件,复制文件
                File.Copy(fsi.FullName, destName);
            else                                    //如果是文件夹,新建文件夹,递归
            {
                Directory.CreateDirectory(destName);
                CopyDirectory(fsi.FullName, destName);
            }
        }
    }
开发者ID:GaoKaiHaHa,项目名称:MyUnityFrameWork,代码行数:22,代码来源:FileTool.cs

示例2: PackBundles

 private static void PackBundles(string sourcePath)
 {
     DirectoryInfo folder = new DirectoryInfo(sourcePath);
     FileSystemInfo[] files = folder.GetFileSystemInfos();
     int length = files.Length;
     for (int i = 0; i < length; i++)
     {
         if(files[i] is DirectoryInfo)
         {
             PackBundles(files[i].FullName);
         }
         else
         {
             if(!files[i].Name.EndsWith(".meta"))
             {
                 SetAssetName(files[i].FullName);
             }
         }
     }
 }
开发者ID:dafei2015,项目名称:UnityScripts,代码行数:20,代码来源:ScenePackage_3D.cs

示例3: AddFileSystem

	public void AddFileSystem() {
		ClearAll ();
		//Debug.LogError("Reading from " + FileLocation);
		MyLabel.text = FileLocation;
		//string[] MyFiles = Directory.GetFileSystemEntries(FileLocation); 
		DirectoryInfo info = new DirectoryInfo(FileLocation);
		FileSystemInfo[] MyFiles = info.GetFileSystemInfos();
		//Debug.LogError ("Found : " + MyFiles.Length);
		for (int i = 0; i < MyFiles.Length; i++) {
			if (!IsFilePathAFolder(MyFiles[i].FullName)) {
				NewEvent(Path.GetFileName(MyFiles[i].FullName));
			}
		}
		for (int i = 0; i < MyFiles.Length; i++) {
			if (IsFilePathAFolder(MyFiles[i].FullName)) {
				NewEvent(Path.GetFileName(MyFiles[i].FullName));
			}
		}
		ResetGui ();
	}
开发者ID:Deus0,项目名称:Zeltex,代码行数:20,代码来源:EventsManager.cs

示例4: LoadAll

    /// <summary>
    /// Loads all save files
    /// </summary>
    /// <returns>A list of all SaveFiles</returns>
    public static List<SaveFile> LoadAll()
    {
        List<SaveFile> saveFiles = new List<SaveFile>();
        BinaryFormatter bf = new BinaryFormatter();

        // Sort files by creation date
        DirectoryInfo di = new DirectoryInfo(Application.persistentDataPath);
        List<FileSystemInfo> files = new List<FileSystemInfo>(di.GetFileSystemInfos("*" + SAVE_FILE_EXTENSION));
        files.Sort(delegate(FileSystemInfo x, FileSystemInfo y)
        {
            return x.CreationTime.CompareTo(y.CreationTime);
        });

        foreach (FileSystemInfo file in files)
        {
            FileStream fileStream = File.Open(file.FullName, FileMode.Open);
            saveFiles.Add((SaveFile)bf.Deserialize(fileStream));
            fileStream.Close();
        }

        return saveFiles;
    }
开发者ID:pkurowsk,项目名称:stratventure,代码行数:26,代码来源:SaveFileUtils.cs

示例5: spAttechDb

    protected void spAttechDb(string mastercon)
    {
        //判断数据库是否能连接上
          if (!checkDatabase(mastercon))
          {
              StringBuilder sb = new StringBuilder();
              sb.Append("create   database    MineSystems2010_PC on ");
              sb.Append("(FileName='" + Server.MapPath("..\\App_Data").ToString() + "\\AllMineDigitize.mdf" + "')");
              string dirp = Server.MapPath("..\\App_Data\\Db").ToString();
              DirectoryInfo mydir = new DirectoryInfo(dirp);
              foreach (FileSystemInfo fsi in mydir.GetFileSystemInfos())
              {
                  if (fsi is FileInfo)
                  {
                      FileInfo fi = (FileInfo)fsi;
                      sb.Append(",(FileName='" + fi.FullName + "')");
                  }
              }
              sb.Append(",(FileName='" + Server.MapPath("..\\App_Data").ToString() + "\\AllMineDigitize_log.ldf" + "') for Attach");

              SqlConnection ThisConnection = new SqlConnection(mastercon);
              SqlCommand cmd = new SqlCommand(sb.ToString(), ThisConnection);
              try
              {
                  ThisConnection.Open();
                  cmd.ExecuteNonQuery();

              }
              catch (Exception ex)
              {

              }
          }
          else
          {

          }
    }
开发者ID:dalinhuang,项目名称:128Web,代码行数:38,代码来源:SetpThd_1.aspx.cs

示例6: ListUploadDirectory

 public static ICollection ListUploadDirectory()
 {
     DirectoryInfo d = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath("~/Upload"));
     return d.GetFileSystemInfos("*.jpg");
 }
开发者ID:artisticcheese,项目名称:MSE,代码行数:5,代码来源:PhotoManager.cs

示例7: runTest

	public bool runTest()
	{
		Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
		int iCountErrors = 0;
		int iCountTestcases = 0;
		String strLoc = "Loc_000oo";
		String strValue = String.Empty;
		try
		{
			DirectoryInfo dir2;
			String dirName = s_strTFAbbrev+"TestDir";
			FileSystemInfo[] fsArr;
			if(Directory.Exists(dirName))
				Directory.Delete(dirName, true);
			strLoc = "Loc_477g8";
			dir2 = new DirectoryInfo(".");
			iCountTestcases++;
			try {
				dir2.GetFileSystemInfos (null);
				iCountErrors++;
				printerr( "Error_2988b! Expected exception not thrown");
			} catch (ArgumentNullException aexc) {
				printinfo( "Info_29087! Caught expected exception, aexc=="+aexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_0707t! Incorrect exception thrown, exc=="+exc.ToString());
			}
			strLoc = "Loc_4yg7b";
			dir2 = new DirectoryInfo(".");
			iCountTestcases++;
			try {
				FileSystemInfo[] strInfos = dir2.GetFileSystemInfos (String.Empty);
				if( strInfos.Length != 0) {                
                    iCountErrors++;
                    printerr( "Error_8ytbm! Unexpected number of file infos returned" + strInfos.Length);
                }
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_2908y! Incorrect exception thrown, exc=="+exc.ToString());
			}
			strLoc = "Loc_1190x";
			dir2 = new DirectoryInfo(".");
			iCountTestcases++;
			try {
				dir2.GetFileSystemInfos ("..ab ab.. .. abc..d\abc.." );
				iCountErrors++;
				printerr( "Error_2198y! Expected exception not thrown");
			} catch (ArgumentException aexc) {
				printinfo( "Info_94170! Caught expected exception, aexc=="+aexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_17888! Incorrect exception thrown, exc=="+exc.ToString());
			}
			strLoc = "Loc_4y982";
			dir2 = Directory.CreateDirectory(dirName);
			fsArr = dir2.GetFileSystemInfos ();
			iCountTestcases++;
			if(fsArr.Length != 0) {
				iCountErrors++;
				printerr("Error_207v7! Incorrect number of files returned");
			}
			strLoc = "Loc_2398c";
			dir2.CreateSubdirectory("TestDir1");
			dir2.CreateSubdirectory("TestDir2");
			dir2.CreateSubdirectory("TestDir3");
			dir2.CreateSubdirectory("Test1Dir1");
			dir2.CreateSubdirectory("Test1Dir2");
			new FileInfo(dir2.FullName + "\\" +"TestFile1").Create();
			new FileInfo(dir2.FullName + "\\" +"TestFile2").Create();
			new FileInfo(dir2.FullName + "\\" +"TestFile3").Create();
			new FileInfo(dir2.FullName + "\\" +"Test1File1").Create();
			new FileInfo(dir2.FullName + "\\" +"Test1File2").Create();
			iCountTestcases++;
			fsArr = dir2.GetFileSystemInfos ("TestFile*");
			iCountTestcases++;
			if(fsArr.Length != 3) {
				iCountErrors++;
				printerr( "Error_1yt75! Incorrect number of files returned");
			}
			String[] names = new String[fsArr.Length];
			int i = 0;
			foreach ( FileSystemInfo f in fsArr) 
				names[i++] = f.Name;
			iCountTestcases++;
			if(Array.IndexOf(names, "TestFile1") < 0) {
				iCountErrors++;
				printerr( "Error_3y775! Incorrect name=="+fsArr[0].Name);
			}
			iCountTestcases++;
			if(Array.IndexOf(names, "TestFile2") < 0) {
				iCountErrors++;
				printerr( "Error_90885! Incorrect name=="+fsArr[1].Name);
			}
			iCountTestcases++;
			if(Array.IndexOf(names, "TestFile3") < 0) {
				iCountErrors++;
				printerr( "Error_879by! Incorrect name=="+fsArr[2].Name);
			}
			fsArr = dir2.GetFileSystemInfos ("*");
			iCountTestcases++;
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co5677getfilesysteminfos_str.cs

示例8: LoadWorlds

	public void LoadWorlds() {
		List<string> GameWorldNames = new List<string> ();
		string FolderName = FileLocator.SaveLocation ("", "", "", "");
		Debug.Log ("Loading world names from: " + FolderName + " At Time: " + Time.time);
		DirectoryInfo info = new DirectoryInfo(FolderName);
		FileSystemInfo[] MyFiles = info.GetFileSystemInfos();
		for (int i = 0; i < MyFiles.Length; i++) {
			// if folder kinda thing
			GameWorldNames.Add (MyFiles[i].Name);
		}
		MyWorldsList.ClearAll();
		for (int i = 0; i < GameWorldNames.Count; i++) {
			if (GameWorldNames[i] != "DefaultFiles")
				MyWorldsList.NewEvent (GameWorldNames[i]);
		}
	}
开发者ID:Deus0,项目名称:Zeltex,代码行数:16,代码来源:GameManager.cs

示例9: miniJS

    /// <summary>
    /// 压缩JS文件
    /// </summary>
    public static void miniJS()
    {
        try
        {
            string pathSrc = HttpRuntime.AppDomainAppPath + "JS/";
            string pathDst = HttpRuntime.AppDomainAppPath + "MiniJS/";
            DirectoryInfo dirInfo = new DirectoryInfo(pathSrc);
            //循环判断当前目录下的文件和目录
            foreach (FileSystemInfo fsi in dirInfo.GetFileSystemInfos())
            {
                FileInfo fi;
                //DirectoryInfo dir;
                string FileName = "";
                string FileExt = "";
                //FileSize = 0;
                //如果是文件
                if (fsi is FileInfo)
                {
                    fi = (FileInfo)fsi;
                    //取得文件名
                    //FileName = fi.Name;
                    //取得文件的扩展名
                    //FileExt = fi.Extension;
                    ////取得文件的大小
                    //FileSize = fi.Length;
                    ////取得文件的最后修改时间
                    //FileModify = fi.LastWriteTime;

                    //删除文件.
                    //fi.Delete();

                    //压缩JS文件
                   // new JavaScriptMinifier().Minify(fi.FullName, pathDst + fi.Name);
                }
                else//否则是目录
                {
                    //dir = (DirectoryInfo)fsi;
                    ////取得目录名
                    //FileName = dir.Name;
                    ////取得目录的最后修改时间
                    //FileModify = dir.LastWriteTime;
                    ////设置文件的扩展名为"文件夹"
                    //FileExt = "文件夹";
                }
            }
        }
        catch
        {
        }
    }
开发者ID:lakeli,项目名称:shizong,代码行数:53,代码来源:Template.cs

示例10: LoadAllSpells

	public void LoadAllSpells() {
		SpellsList.Clear ();
		string FolderName = FileLocator.SaveLocation (GameName, "", "Spells/", "");
		Debug.Log ("Loading spells from: " + FolderName + " At Time: " + Time.time);
		DirectoryInfo info = new DirectoryInfo(FolderName);
		FileSystemInfo[] MyFiles = info.GetFileSystemInfos();
		for (int i = 0; i < MyFiles.Length; i++) {
			//Debug.LogError ("     Loading spell from: " + MyFiles[i].FullName);
			if (MyFiles[i].Name.Contains(".spe")) {
				string SaveFileName = FileLocator.SaveLocation (GameName, "Spell" + i.ToString (), "Spells/", ".spe");
				Debug.Log ("    Loading spell from: " + SaveFileName);
				if (File.Exists (SaveFileName)) {
					SpellData NewSpell = LoadSpellFromText(SaveFileName);
					if (NewSpell != null) {
						SpellsList.Add (new Spell (NewSpell));
					}
				} else {
					Debug.Log (SaveFileName + " does not exist :/aerioajer" );
				}
			} else {
				Debug.Log ("     Spell doesn't contain .spe! " );
			}
		}
	}
开发者ID:Deus0,项目名称:Zeltex,代码行数:24,代码来源:SpellManager.cs

示例11: CreateLocalFileDict

    static void CreateLocalFileDict(string path)
    {
        List<string> localFileList = new List<string>();
        DirectoryInfo folder = new DirectoryInfo(path);
        FileSystemInfo[] files = folder.GetFileSystemInfos();
        int length = files.Length;
        for (int i = 0; i < length; i++)
        {
            if (files[i] is DirectoryInfo)
            {
                CreateLocalFileDict(files[i].FullName);
            }
            else if (files[i].Name.EndsWith(".unity3d"))
            {
                localFileList.Add(files[i].FullName);
            }
        }

        for (int i = 0; i < localFileList.Count; i++)
        {
            string _source = CommonUtil.Instance.ReplaceSlash(localFileList[i]);
            localFileList[i] = _source.Substring(Application.streamingAssetsPath.Length + CommonUtil.Instance.GetRuntimePlatform().Length + 2);

            //Debug.Log(localFileList[i]);
            string key = localFileList[i].Substring(0, localFileList[i].Length - 41);
            string value = localFileList[i].Substring(localFileList[i].Length - 40, 32);

            //Debug.Log("key: " + key + ", value: " + value);
            localFileDict.Add(key, value);
        }
    }
开发者ID:karl4711,项目名称:unitytest,代码行数:31,代码来源:AssetBundleBuilder.cs

示例12: BT_Query_Click

    protected void BT_Query_Click(object sender, EventArgs e)
    {
        Location_1 = Location + DL_F.SelectedValue + "/";
        if (Directory.Exists(Location_1) == false)
        {
            System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "tixin", "alert('该文件不存在或路径错误!')", true);
        }
        else
        {
            DirectoryInfo di = new DirectoryInfo(Location_1);
            FileSystemInfo[] dis = di.GetFileSystemInfos();//.ToString() + Convert.ToString(di.CreationTime);
            if (dis.Length < 1)
            {
                System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "tixin", "alert('该文件夹是空文件夹!')", true);
            }
            else
            {
                ListBox1.DataSource = dis;
                ListBox1.DataBind();
                if (Session["wenjian"] != null)
                {

                    Session.Remove("wenjian");
                }
                //System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "tixin", "alert('检索成功,列表为该路径的文件和目录!')", true);
            }
        }
    }
开发者ID:wra222,项目名称:testgit,代码行数:28,代码来源:UploadFile.aspx.cs

示例13: TestGetFileSystemInfosWithSearchRecursiveNoResults

		public void TestGetFileSystemInfosWithSearchRecursiveNoResults()
		{
			var di = new DirectoryInfo(longPathDirectory);
			var randomFileName = Path.GetRandomFileName();
			var newDi = di.CreateSubdirectory(randomFileName);
			try
			{
				var fi = new FileInfo(Path.Combine(newDi.FullName, "filename"));
				using (fi.Create())
				{
				}
				try
				{
					Assert.AreEqual(0, di.GetFileSystemInfos("gibberish", SearchOption.AllDirectories).Count());
				}
				finally
				{
					fi.Delete();
				}
			}
			finally
			{
				newDi.Delete(true);
			}
		}
开发者ID:HMartyrossian,项目名称:LongPath,代码行数:25,代码来源:DirectoryInfoTests.cs

示例14: GetDirectorySize

 /// <summary>
 /// 递归文件夹大小
 /// </summary>
 /// <param name="dirp"></param>
 /// <returns></returns>
 private long GetDirectorySize(string dirp)
 {
     DirectoryInfo mydir = new DirectoryInfo(dirp);
     foreach (FileSystemInfo fsi in mydir.GetFileSystemInfos())
     {
         if (fsi is FileInfo)
         {
             FileInfo fi = (FileInfo)fsi;
             dirSize += fi.Length;
         }
         else
         {
             DirectoryInfo di = (DirectoryInfo)fsi;
             string new_dir = di.FullName;
             GetDirectorySize(new_dir);
         }
     }
     return dirSize;
 }
开发者ID:89sos98,项目名称:m-p-s,代码行数:24,代码来源:default.aspx.cs

示例15: RenderList

    protected String RenderList()
    {
        AccountInfo cu = ServerImpl.Instance.GetCurrentUser(Context);

        StringBuilder builder = new StringBuilder();
        string root = String.Format("/{0}/Home", GroupInfo.ID);
        if (!Directory.Exists(root)) Directory.CreateDirectory(root);
        DirectoryInfo di = new DirectoryInfo(root);
        foreach (FileSystemInfo fsi in di.GetFileSystemInfos())
        {
            if ((fsi.Attributes & FileAttributes.Directory) != FileAttributes.Directory)
            {
                FileInfo fi = fsi as FileInfo;
                string temp = "";
                long size = fi.Length;
                if (size > 1024 * 1024 * 1024) temp = String.Format("{0:#######0.00}GB", (double)size / (1024 * 1024 * 1024));
                else if (size > 1024 * 1024) temp = String.Format("{0:#######0.00}MB", (double)size / (1024 * 1024));
                else if (size > 1024) temp = String.Format("{0:#######0.00}KB", (double)size / 1024);
                else temp = size.ToString() + "B";
                builder.AppendFormat(
                    RowFormat,
                    fi.Name, fi.FullName,
                    (GroupInfo.SubType == 1 || (GroupInfo.SubType == 0 && GroupInfo.Creator == cu.ID)) ? String.Format("<a href='javascript:Delete({0})'>删除</a>", Utility.RenderJson(fi.Name)) : "",
                    temp, Microsoft.JScript.GlobalObject.escape(fi.FullName)
                );
            }
        }
        return builder.ToString();
    }
开发者ID:cyyt,项目名称:Lesktop,代码行数:29,代码来源:Share.aspx.cs


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