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


C# DirectoryInfo.GetFiles方法代码示例

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


在下文中一共展示了DirectoryInfo.GetFiles方法的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: Precache

    public static void Precache()
    {
        Synthesizer synthesizer = GameObject.FindObjectOfType<Synthesizer>();

        DirectoryInfo dir = new DirectoryInfo("Assets/Resources/Midis");
        FileInfo[] info = dir.GetFiles("*.txt");
        info.Select(f => f.FullName).ToArray();

        List<GUIContent> content = new List<GUIContent>();
        foreach (FileInfo f in info)
        {
            string file = f.Name;
            content.Add(new GUIContent(file));
        }

        info = dir.GetFiles("*.bytes");
        info.Select(f => f.FullName).ToArray();
        foreach (FileInfo f in info)
        {
            string file = f.Name;
            content.Add(new GUIContent(file));
        }

        synthesizer.comboBoxList = content.ToArray();
    }
开发者ID:calvinbaart,项目名称:unity_synthesizer,代码行数:25,代码来源:MenuItems.cs

示例4: btn_Click

    protected void btn_Click(object sender, EventArgs e)
    {
        DirectoryInfo dir = new DirectoryInfo("C:\\IlinkbayForder");
        if (!dir.Exists)
            dir.Create();
        foreach (FileInfo file in dir.GetFiles())
        {
            file.Delete();
        }
        System.IO.FileStream fileReportHeader = new System.IO.FileStream(@"C:\\IlinkbayForder\\heReportHeader.rtf", System.IO.FileMode.Create);
        heReportHeader.Export(HtmlEditorExportFormat.Rtf, fileReportHeader);
        System.IO.FileStream fileReportFooter = new System.IO.FileStream(@"C:\\IlinkbayForder\\heReportFooter.rtf", System.IO.FileMode.Create);
        heReportFooter.Export(HtmlEditorExportFormat.Rtf, fileReportFooter);
        fileReportHeader.Close();
        fileReportFooter.Close();

        string rtfFooter = System.IO.File.ReadAllText(@"C:\\IlinkbayForder\\heReportFooter.rtf");
        string rtfHeader = System.IO.File.ReadAllText(@"C:\\IlinkbayForder\\heReportHeader.rtf");

        SqlHelper.ExecuteScalar( DataServices.ConnectString, "SY_exportsetting_Update", int.Parse(Session["ID"].ToString()), rtfHeader, heReportHeader.Html, rtfFooter, heReportFooter.Html, chkLandscape.Checked, cmbPagesKind.Value, txtFileName.Text);

        foreach (FileInfo file in dir.GetFiles())
        {
            file.Delete();
        }
        dir.Delete();
        CacheObject.buildCache_globalExportSetting();
    }
开发者ID:trantrung2608,项目名称:ilinkbay,代码行数:28,代码来源:SettingReportHeader.aspx.cs

示例5: BuildUnityPackage

    public static void BuildUnityPackage()
    {
        var lIOSPluginsPath = @"Assets/Editor/WebP/iOS/src";

        Directory.CreateDirectory(lIOSPluginsPath);

        var lSourceDirectory = new DirectoryInfo("../webp/libwebp/src");

        var lSrcFiles       = lSourceDirectory.GetFiles("*.c", SearchOption.AllDirectories);
        var lHeaderFiles    = lSourceDirectory.GetFiles("*.h", SearchOption.AllDirectories);

        for (int lIndex = 0; lIndex < lSrcFiles.Length; ++lIndex)
        {
            string lRelativePath = lSrcFiles[lIndex].FullName.Substring(lSourceDirectory.FullName.Length + 1);
            Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(lIOSPluginsPath, lRelativePath)));
            File.Copy(lSrcFiles[lIndex].FullName, Path.Combine(lIOSPluginsPath, lRelativePath), true);
        }

        for (int lIndex = 0; lIndex < lHeaderFiles.Length; ++lIndex)
        {
            string lRelativePath = lHeaderFiles[lIndex].FullName.Substring(lSourceDirectory.FullName.Length + 1);
            Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(lIOSPluginsPath, lRelativePath)));
            File.Copy(lHeaderFiles[lIndex].FullName, Path.Combine(lIOSPluginsPath, lRelativePath), true);
        }

        AssetDatabase.Refresh();

        AssetDatabase.ExportPackage(m_PackageInputPaths, m_PackageOutputPath, ExportPackageOptions.Recurse);

        Directory.Delete(lIOSPluginsPath, true);

        AssetDatabase.Refresh();
    }
开发者ID:sonygod,项目名称:webp-unity3d,代码行数:33,代码来源:BuildPackage.cs

示例6: DownloadFileToDisk

    public void DownloadFileToDisk()
    {
        Driver.Navigate().GoToUrl("http://the-internet.herokuapp.com/download");
        Driver.FindElement(By.CssSelector(".example a")).Click();
        Thread.Sleep(2000);

        DirectoryInfo DownloadFolder = new DirectoryInfo(FolderPath);
        Assert.IsTrue(DownloadFolder.GetFiles().Length > 0, "File not downloaded");
        foreach(FileInfo file in DownloadFolder.GetFiles())
        {
            Assert.IsTrue(file.Length > 0, "File empty");
        }
    }
开发者ID:GruLab,项目名称:elemental-selenium-tips,代码行数:13,代码来源:FileDownload.cs

示例7: CreateIt

    public static void CreateIt()
    {
        string vs_root = Directory.GetCurrentDirectory();

        //write solution file out to disk.
        StreamWriter sw = new StreamWriter(Path.Combine(vs_root,GetProjectName() + ".sln"));
        sw.Write(GetSolutionText());
        sw.Close();

        //write first part of our project file.
        sw = new StreamWriter(Path.Combine(vs_root,GetProjectName() + ".csproj"));
        sw.Write(GetProjectFileHead());

        //add a line for each .cs file found.
        DirectoryInfo di = new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(),"Assets"));
        FileInfo[] fis = di.GetFiles("*.cs",SearchOption.AllDirectories);
        foreach (FileInfo fi in fis)
        {
            string relative = fi.FullName.Substring(di.FullName.Length+1);
            relative = relative.Replace("/", "\\");
            sw.WriteLine("     <Compile Include=\"Assets\\"+relative+"\" />");
        }

        //add a line for each shader found.
        fis = di.GetFiles("*.shader", SearchOption.AllDirectories);  //make recursive
        foreach (FileInfo fi in fis)
        {
            string relative = fi.FullName.Substring(di.FullName.Length + 1);
            relative = relative.Replace("/", "\\");
            sw.WriteLine("     <None Include=\"Assets\\" + relative + "\" />");
        }

        //and write the tail of our projectfile.
        sw.Write(GetProjectFileTail());
        sw.Close();

        //why is System.IO.FileInfo always struggling with me?
        FileInfo dll = new FileInfo(GetAssemblyPath(typeof (GameObject)));
        string assemblyfolder = dll.Directory.ToString();

        FileInfo unityengine = new FileInfo(assemblyfolder+"\\UnityEngine.xml");
        FileInfo unityeditor = new FileInfo(assemblyfolder + "\\UnityEditor.xml");

        if ((!unityengine.Exists || !unityeditor.Exists) && !stopwining)
        {
            EditorUtility.DisplayDialog("Documentation missing.",
                                        "For inline documentation in visual studio, download this archive:\nhttp://www.unifycommunity.com\n/wiki/images/d/d2/Visual_Studio_docs_2.5.zip and unpack it into " +
                                        unityengine.Directory.FullName,"OK","OK");
            stopwining = true;
        }
    }
开发者ID:kjaylee,项目名称:unitylightmapper,代码行数:51,代码来源:SyncVisualStudioSolution.cs

示例8: addSubDirectory

 private void addSubDirectory(DirectoryInfo directory)
 {
     for (int i = 0; i < directory.GetFiles().Length; i++)
     {
         foreach (FileInfo fi in directory.GetFiles(pattern[i]))
         {
             AddHtmlDocument(fi.FullName);
         }
     }
     foreach (DirectoryInfo di in directory.GetDirectories())
     {
         addSubDirectory(di);
     }
 }
开发者ID:xueshijun,项目名称:0.Undergraduation-Design,代码行数:14,代码来源:IntranetIndexer.cs

示例9: LoadFolders

    public void LoadFolders()
    {
        if (Directory.Exists(this.RealImagePath)) {
            DirectoryInfo _currentFolder = new DirectoryInfo(this.current_path.Value);
            DirectoryInfo[] _subs = _currentFolder.GetDirectories();

            this.FolderList.DataSource = _subs;
            this.FolderList.DataBind();
            //get files in patterns
            string[] pattern = { "*.jpg", "*.jpeg", "*.gif" ,"*.png","*.bmp"};
            List<FileInfo> _imagesFound = new List<FileInfo>();
            foreach (string filter in pattern) {
                _imagesFound.AddRange(_currentFolder.GetFiles(filter));
            }
            this.FileList.DataSource = _imagesFound;
            this.FileList.DataBind();

            //Response.Write(_currentFolder.FullName);
            //Response.Write(Server.MapPath(this._rootPath));

            if (!_currentFolder.FullName.Equals( Server.MapPath(this._rootPath),StringComparison.InvariantCulture))
            {
                DirectoryInfo _parent = _currentFolder.Parent;

                this.go_up_btn.CommandArgument = _parent.FullName + "\\";
                this.go_up_btn.Visible = true;

            }
            else
            {
                this.go_up_btn.Visible = false;
            }
            this.current_folder_name_lbl.Text = this.current_path.Value;
        }
    }
开发者ID:abdul-baten,项目名称:hbcms,代码行数:35,代码来源:FilesAndForlders.aspx.cs

示例10: ShowSaveGames

    public void ShowSaveGames(bool show) {
        pauseMenu.transform.FindChild("PauseButtonPanel").GetComponent<CanvasGroup>().alpha = System.Convert.ToSingle(!show);
        pauseMenu.transform.FindChild("PauseButtonPanel").GetComponent<CanvasGroup>().interactable = !show;
        pauseMenu.transform.FindChild("PauseButtonPanel").GetComponent<CanvasGroup>().blocksRaycasts = !show;

        pauseMenu.transform.FindChild("LoadGamePanel").GetComponent<CanvasGroup>().alpha = System.Convert.ToSingle(show);
        pauseMenu.transform.FindChild("LoadGamePanel").GetComponent<CanvasGroup>().interactable = show;
        pauseMenu.transform.FindChild("LoadGamePanel").GetComponent<CanvasGroup>().blocksRaycasts = show;

        var children = new List<GameObject>();
        foreach (Transform child in pauseMenu.transform.FindChild("LoadGamePanel/Scroll View/Viewport/Content"))  {
            children.Add(child.gameObject);
        }
        children.ForEach(child => Destroy(child));

        DirectoryInfo info = new DirectoryInfo(Application.persistentDataPath);
        FileInfo[] files = info.GetFiles("*.fsf").OrderByDescending(p => p.CreationTime).ToArray();
        foreach (FileInfo file in files)
        {
            FileInfo localFile = file;
            string[] parts = System.IO.Path.GetFileNameWithoutExtension(localFile.Name).Split('_');
            GameObject go = Instantiate(Resources.Load("UIPrefabs/SaveGameButton"), Vector3.zero, Quaternion.identity) as GameObject;
            go.transform.SetParent(pauseMenu.transform.FindChild("LoadGamePanel/Scroll View/Viewport/Content"));
            go.transform.localScale = Vector3.one;
            if (parts.Length == 4) {
                go.transform.FindChild("GameDetails").GetComponent<TextMeshProUGUI>().text = string.Format("Administrator : {0}\n{1}, {2} {3}", parts[0], parts[1], parts[2], parts[3].Replace('-', ':'));
            }
            else {
                go.transform.FindChild("GameDetails").GetComponent<TextMeshProUGUI>().text = "UNRECOGNIZED SAVE FILE FORMAT";
            }
            go.transform.GetComponent<Button>().onClick.AddListener(delegate {
                LoadGame(Application.persistentDataPath + "/" + localFile.Name);
            });
        }
    }
开发者ID:riscvul,项目名称:SCP_Game_Prototype,代码行数:35,代码来源:PauseMenuUI.cs

示例11: getFiles

	internal void getFiles()
	{
		if (System.IO.Directory.Exists(myPath))
		{
			DirectoryInfo dir = new DirectoryInfo(myPath);
			Debug.Log("Looking for files in dir: "+myPath);
			
			FileInfo[] info = dir.GetFiles("*."+extention);
			
			// Get number of files, and set the length for the texture2d array
			int totalFiles =  info.Length;
			slides = new Texture2D[totalFiles];
			
			int i = 0;
			
			//Read all found files
			foreach (FileInfo f in info)
			{
				string filePath = f.Directory + "/" + f.Name;
				Debug.Log("["+i+"] file found: "+filePath);
				
				var bytes     = System.IO.File.ReadAllBytes(filePath);
				var tex         = new Texture2D(1, 1);
				
				tex.LoadImage(bytes);
				slides[i] = tex;
				
				i++;
			}
		}
		else
		{
			Debug.Log ("Directory DOES NOT exist! ");
		}
	}
开发者ID:sw5813,项目名称:VRConference,代码行数:35,代码来源:VidScript.cs

示例12: 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

示例13: Handler

    public void Handler()
    {
        Byte[] byteSent = new Byte[1];
        Byte[] bytesReceived = new Byte[1];
        DirectoryInfo directoryInfo;

        int bytes;
        String data = "";

        String currentByteString = "";
        char currentByteChar;

        while(true)
        {
            while (true)
            {
                bytes = cSocket.Receive(bytesReceived, bytesReceived.Length, 0);

                // Console.WriteLine(Encoding.ASCII.GetString(bytesReceived, 0, bytes));
                currentByteString = System.Text.Encoding.ASCII.GetString(bytesReceived, 0, bytes);
                currentByteChar = currentByteString[0];
                // Console.WriteLine(currentByteChar);

                if (currentByteChar == '\0')
                {
                    Console.WriteLine("*** DEBUG: Found null character, returning directory contents...");

                    break;
                }

                data += currentByteString;

                Console.WriteLine("*** DEBUG: Current data: " + data);
            }

            //Process the data sent by the client.
            if(data == "exit")
            {
                break;
            }

            directoryInfo = new DirectoryInfo(data);

            FileInfo[] fileArray = directoryInfo.GetFiles();
            string files = "";

            foreach (FileInfo fileInfo in fileArray)
            {
                files += fileInfo.Name;
                files += "\n";
            }

            byte[] msg = System.Text.Encoding.ASCII.GetBytes(files);

            // Send request to the server
            cSocket.Send(msg, msg.Length, 0);
        }

        cSocket.Close();
    }
开发者ID:sinapsist,项目名称:BCIT,代码行数:60,代码来源:TCPListener.cs

示例14: TreverseDir

    private static void TreverseDir(DirectoryInfo dir)
    {

        var currentFolder = new CustomFolder(dir.Name);
        folderStructure.Add(currentFolder);
        var folders = dir.GetDirectories();
        var files = dir.GetFiles();

        try
        {
            foreach (var file in files)
            {
                var currentFile = new CustomFile(file.Name, file.Length);
                currentFolder.AddFile(currentFile);
            }

            foreach (var folder in folders)
            {
                var childFolder = new CustomFolder(folder.Name);

                currentFolder.AddFolder(childFolder);
                TreverseDir(folder);
            }
        }
        catch (Exception)
        {
            Console.WriteLine("Access denied! ");
        }
    }
开发者ID:aleks-todorov,项目名称:HomeWorks,代码行数:29,代码来源:Application.cs

示例15: LoadDirectoriesRecursive

 private static List<Texture> LoadDirectoriesRecursive(string folderPath, List<Texture> textures)
 {
     DirectoryInfo folder = new DirectoryInfo(folderPath);
     if (!folder.Exists)
         return textures;
     DirectoryInfo[] subfolders = folder.GetDirectories();
     FileInfo[] files = folder.GetFiles();
     foreach (FileInfo file in files)
     {
         string extension = file.Extension.ToLower();
         if (!extension.Equals(".png") && !extension.Equals(".jpg"))
             continue;
         string url = file.FullName;
         string name = Path.GetFileNameWithoutExtension(url);
         Texture tex = ImportTextureLocal(url);
         tex.name = name;
         textures.Add(tex);
     }
     foreach (DirectoryInfo subfolder in subfolders)
     {
         string fullName = subfolder.FullName;
         textures = LoadDirectoriesRecursive(fullName, textures);
     }
     return textures;
 }
开发者ID:Jay2645,项目名称:ludum-dare-7dRTS,代码行数:25,代码来源:ExternalDL.cs


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