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


C# DirectoryInfo.GetFileSystemInfos方法代码示例

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


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

示例1: FileAndFolderNamesIn

 public IEnumerable<string> FileAndFolderNamesIn(string path, string searchPattern = null)
 {
     var directoryInfo = new DirectoryInfo(path);
     if (string.IsNullOrEmpty(searchPattern))
     {
         return directoryInfo.GetFileSystemInfos().Select(info => info.Name).ToList();
     }
     return directoryInfo.GetFileSystemInfos(searchPattern).Select(info => info.Name).ToList();
 }
开发者ID:pedershk,项目名称:dotnetprograms,代码行数:9,代码来源:FileSystemManager.cs

示例2: ImporterData

        private void ImporterData(object source, System.Timers.ElapsedEventArgs e)
        {
            String FilePath = ConfigurationManager.AppSettings["ImporterService.FilePath"];
            String BakPath = ConfigurationManager.AppSettings["ImporterService.BakPath"];
            int hour = int.Parse(ConfigurationManager.AppSettings["ImporterService.hour"]);
            if (hour == DateTime.Now.Hour) {
                MasterDataBLL masterdatabll = new MasterDataBLL();
                LogBLL logbll = new LogBLL();
                DirectoryInfo mydir = new DirectoryInfo(FilePath);
                //0 SKU  1 Item 2 Customer
                FileSystemInfo[] SKUfile = mydir.GetFileSystemInfos("IIM*");
                if (SKUfile.Length > 0) {
                    ImportTxtData(0, SKUfile);
                } else {
                    int logId = logbll.InsertImportLog(0, "未找到文件", 1, 0, 0, 1);
                    logbll.InsertImportLogDetail(logId, 0, "未找到SKU文件!");
                }
                FileSystemInfo[] Itemfile = mydir.GetFileSystemInfos("HPC*");
                if (Itemfile.Length > 0) {
                    ImportTxtData(1, Itemfile);
                } else {
                    int logId = logbll.InsertImportLog(1, "未找到文件", 1, 0, 0, 1);
                    logbll.InsertImportLogDetail(logId, 0, "未找到Item文件!");
                }
                FileSystemInfo[] Customerfile = mydir.GetFileSystemInfos("RCM*");
                if (Customerfile.Length > 0) {
                    ImportTxtData(2, Customerfile);
                } else {
                    int logId = logbll.InsertImportLog(2, "未找到文件", 1, 0, 0, 1);
                    logbll.InsertImportLogDetail(logId, 0, "未找到Customer文件!");
                }

                //FileSystemInfo[] DeliveryGoods = mydir.GetFileSystemInfos("DeliveryGoods*");
                //if (DeliveryGoods.Length > 0) {
                //    ImportTxtData(3, Customerfile);
                //} else {
                //    int logId = logbll.InsertImportLog(3, "未找到文件", 1, 0, 0, 1);
                //    logbll.InsertImportLogDetail(logId, 0, "未找到Delivery Goods文件!");
                //}

                FileSystemInfo[] APHPayment = mydir.GetFileSystemInfos("APHPAY*");
                if (APHPayment.Length > 0) {
                    ImportTxtData(4, APHPayment);
                } else {
                    int logId = logbll.InsertImportLog(4, "未找到文件", 1, 0, 0, 1);
                    logbll.InsertImportLogDetail(logId, 0, "未找到APHPAY文件!");
                }

                foreach (FileSystemInfo file in mydir.GetFileSystemInfos()) {
                    File.Move(file.FullName, BakPath + file.Name);
                }
            }
        }
开发者ID:hijoy,项目名称:CPL_ERS,代码行数:53,代码来源:ImporterService.cs

示例3: Show

        private void Show(DirectoryInfo di, int indent)
        {
            _logger.InfoLine(string.Format($"{new String(' ', indent * 2)}{di.Name}/"));
            foreach (var dir in di.GetFileSystemInfos().OfType<DirectoryInfo>())
            {
                Show(dir, indent + 1);
            }
            var fileInfos = di.GetFileSystemInfos(Filter).OfType<FileInfo>();
            foreach (var fi in fileInfos)
            {
                string encoding = GetEncoding(fi);
                _logger.InfoLine(string.Format($"{new String(' ', indent * 2)}{fi.Name}|{fi.Length}|{encoding}"));
            }

        }
开发者ID:moonwa,项目名称:moonlit.tools,代码行数:15,代码来源:FileList.cs

示例4: ShowDir

        private string ShowDir(string dirName, string str)
        {
            string fullName = "/templates/_shop/" + dirName;

            fullName = Server.MapPath(fullName);

            DirectoryInfo dirInfo = new DirectoryInfo(fullName);

            System.Text.StringBuilder sbhtml = new System.Text.StringBuilder("");

            foreach (FileSystemInfo subDir in dirInfo.GetFileSystemInfos())
            {
                if (subDir.GetType().Name == "DirectoryInfo")
                {
                    if (!IsShowDir(subDir)) continue;
                    sbhtml.Append("<li>" + str + "<img src=\"../images/temp02.GIF\" alt=\"�ļ���\">" + subDir.Name + "</li>");

                    sbhtml.Append(ShowDir(dirName + "/" + subDir.Name, "--" + str));
                }
                else
                {
                    if (str.Equals("")) continue;

                    if (subDir.Extension != ".htm" && subDir.Extension != ".css") continue;

                    sbhtml.Append("<li>" + str + "<img src=\"../images/temp.GIF\" alt=\"ģ��\">[<a href=\"javascript:TemplatesEdit('../../templates/_shop/" + dirName + "/" + subDir.Name + "');\">�༭</a>]");
                    sbhtml.Append("<label for=\"temp01\">" + subDir.Name + "</label></li>");
                }
            }

            return sbhtml.ToString();
        }
开发者ID:xyecom,项目名称:AMS,代码行数:32,代码来源:ShopTemplateTree.aspx.cs

示例5: GetFilenames

        // TODO: 可以尝试用通用版本的 GetFileNames() 加上回调函数定制出本函数
        // 获得一个子目录内的所有文件名和所有下级子目录内的文件名
        // parameters:
        //      bLastWriteTime  是否在文件名后面附加此文件的最后修改时间
        static List<string> GetFilenames(string strDir,
            bool bLastWriteTime = false,
            bool bExcludeBackupFile = true)
        {
            List<string> results = new List<string>();

            DirectoryInfo di = new DirectoryInfo(strDir);
            FileSystemInfo[] subs = di.GetFileSystemInfos();

            for (int i = 0; i < subs.Length; i++)
            {
                FileSystemInfo sub = subs[i];
                if ((sub.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    results.AddRange(GetFilenames(sub.FullName, bLastWriteTime, bExcludeBackupFile));
                    continue;
                }

                if (bExcludeBackupFile == true && FileUtil.IsBackupFile(sub.FullName) == true)
                    continue;

                if (bLastWriteTime == true)
                    results.Add(sub.FullName + "|" + DateTimeUtil.Rfc1123DateTimeStringEx(sub.LastWriteTime));
                else
                    results.Add(sub.FullName);
            }

            return results;
        }
开发者ID:renyh1013,项目名称:dp2,代码行数:33,代码来源:AppSystemParameter.cs

示例6: CalculateFinalName

        public static string CalculateFinalName(DirectoryInfo container, string newName)
        {
            Require.NotNull(container, "container");
            Require.NotNullOrEmpty(newName, "newName");

            if (!container.Exists)
            {
                return newName;
            }

            string ext = Path.GetExtension(newName);
            string newNameWithoutExt = newName.Substring(0, newName.Length - ext.Length);
            string finalNameWithoutExt = newNameWithoutExt;

            var infos = container.GetFileSystemInfos(ext.Length > 0 ? finalNameWithoutExt + ext : finalNameWithoutExt);
            int i = 1;

            while (infos.Length == 1)
            {
                finalNameWithoutExt = newNameWithoutExt + "(" + i + ")";

                infos = container.GetFileSystemInfos(ext.Length > 0 ? finalNameWithoutExt + ext : finalNameWithoutExt);
                ++i;
            }

            return finalNameWithoutExt + ext;
        }
开发者ID:sigcms,项目名称:Seeger,代码行数:27,代码来源:FileExplorer.cs

示例7: DeleteFolder

        /// <summary>
        /// 删除指定路径下的文件及文件夹
        /// </summary>
        /// <param name="path">指定路径</param>
        /// <returns>成功返回真,否则返回假</returns>
        public static bool DeleteFolder(string path)
        {
            try
            {
                DirectoryInfo di = new DirectoryInfo(path);

                FileSystemInfo[] fsi = di.GetFileSystemInfos();

                foreach (FileSystemInfo tempFsi in fsi)
                {
                    if (tempFsi is DirectoryInfo)
                    {   // 删除文件夹
                        Directory.Delete(tempFsi.FullName, true);
                    }
                    else if (tempFsi is FileInfo)
                    {    // 删除文件
                        tempFsi.Delete();
                    }
                }

                return true;
            }
            catch
            {
                return false;
            }
        }
开发者ID:lkwz323,项目名称:CodeGeneratorForSQLite,代码行数:32,代码来源:Main.cs

示例8: CopyDirectoryAndReplaceBatFileText

 //文件夹复制函数编写
 private static void CopyDirectoryAndReplaceBatFileText(string source, string destination, bool needReplace, string replaceWithText)
 {
     DirectoryInfo info = new DirectoryInfo(source);
     foreach (FileSystemInfo fsi in info.GetFileSystemInfos())
     {
         //目标路径destName = 目标文件夹路径 + 原文件夹下的子文件(或文件夹)名字
         //Path.Combine(string a ,string b) 为合并两个字符串
         String destName = Path.Combine(destination, fsi.Name);
         //如果是文件类,就复制文件
         if (fsi is System.IO.FileInfo)
         {
             if (File.Exists(destName))
             {
                 FileAttributes fileAttributes = File.GetAttributes(destName);
                 if ((fileAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                 {
                     File.SetAttributes(destName, FileAttributes.Normal);
                 }
             }
             File.Copy(fsi.FullName, destName, true);
         }
         else //如果不是 则为文件夹,继续调用文件夹复制函数,递归
         {
             Directory.CreateDirectory(destName);
             CopyDirectoryAndReplaceBatFileText(fsi.FullName, destName, needReplace, replaceWithText);
         }
     }
 }
开发者ID:BlueSky007,项目名称:Demo55,代码行数:29,代码来源:CopyHelper.cs

示例9: RefreshFilesList

        public void RefreshFilesList(string directory)
        {
            IList<FileSystemInfo> visibleThings = new List<FileSystemInfo>();
            var dir = new DirectoryInfo(directory);

            try
            {
                if (dir.ToString()!="/")
                    visibleThings.Add(dir.Parent);
                foreach (var item in dir.GetFileSystemInfos().Where(item => item.IsVisible()))
                {
                    bool b;
                    if (item.IsDirectory()) b = true; else b = txt(item.Name);
                    if (b) visibleThings.Add(item);
                }
            }
            catch (Exception ex)
            {
                Log.Error("FileListFragment", "Нет доступа к директории " + _directory.FullName + "; " + ex);
                Toast.MakeText(Activity, "Проблема доступа к директории " + directory, ToastLength.Long).Show();
                return;
            }

            _directory = dir;

            _adapter.AddDirectoryContents(visibleThings);

            ListView.RefreshDrawableState();

            Log.Verbose("FileListFragment", "Показан контент директории {0}.", directory);
        }
开发者ID:dariadr,项目名称:TextToSpeach,代码行数:31,代码来源:FileListFragment.cs

示例10: 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);
            if (!Directory.Exists(destinationPath))
            {
                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, true);
                    FileInfo file = new FileInfo(destName);
                    file.IsReadOnly = false;
                }
                else                                    //如果是文件夹,新建文件夹,递归
                {
                    // Directory.CreateDirectory(destName);
                    CopyDirectory(fsi.FullName, destName);
                }
            }
        }
开发者ID:cat80,项目名称:CommonRole,代码行数:30,代码来源:FileDirecotryHelper.cs

示例11: Handle

        /// <summary>
        /// Tries to handle request.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <returns>
        /// The WebServer.BusinessLogic.Response.
        /// </returns>
        public override Response Handle(Request request)
        {
            if (request.HttpPath.EndsWith("/"))
            {
                string path = Configurator.Instance.RelativeWwwPath + request.HttpPath.Replace("/", "\\");
                if(!Directory.Exists(path))
                {
                    return NextHandler.Handle(request);
                }
                DirectoryInfo directory = new DirectoryInfo(path);
                List<FileSystemInfo> descendants = new List<FileSystemInfo>();
                descendants.AddRange(directory.GetFileSystemInfos());

                if (descendants.Select(desc => desc.Name).Contains("index.html"))
                {
                    request.HttpPath += "index.html";
                    return NextHandler.Handle(request);
                }

                string webPage = this.CreateWebPage(descendants, request);

                Response toReturn = new Response("text/html", request.HttpVersion, Encoding.UTF8.GetBytes(webPage));
                if (Configurator.Instance.UseResponseCompression && request.AcceptEncoding == EnumAcceptEncoding.Gzip)
                {
                    toReturn.Data = GzipCompress(toReturn.Data);
                    toReturn.ContentEncoding = "gzip";
                }

                return toReturn;
            }

            return NextHandler.Handle(request);
        }
开发者ID:taraspikh,项目名称:cs-webserver,代码行数:42,代码来源:DirectoryHandler.cs

示例12: GetAllFiles

 /// <summary>
 /// 获取所选文件夹的文件
 /// </summary>
 /// <param name="dir"></param>
 /// <returns></returns>
 public static void GetAllFiles(DirectoryInfo dir)
 {
     List<HistoryDto> listHis = new List<HistoryDto>();
     FileSystemInfo[] fileinfo = dir.GetFileSystemInfos();
     foreach (FileSystemInfo info in fileinfo)
     {
         if (info is DirectoryInfo)
         {
             GetAllFiles((DirectoryInfo)info);
         }
         else
         {
             var extension = info.Extension;
             if (extension.Equals(".dwg") || extension.Equals(".dwt") || extension.Equals(".dws") || extension.Equals(".dxf"))
             {
                 if (Util.GetDrwingsDto(info.Name) == null)
                 {
                     HistoryDto dto = new HistoryDto();
                     dto.Id = Guid.NewGuid().ToString();
                     dto.FileName = info.Name;
                     dto.FilePath = info.FullName.Replace("\\", "\\\\");
                     dto.FileStatus = "未处理";
                     listHis.Add(dto);
                 }
             }
         }
     }
     InsertHistory(listHis);
     listHis.Clear();
 }
开发者ID:huayancreate,项目名称:HYAutoCADConvert,代码行数:35,代码来源:Util.cs

示例13: RefreshFilesList

        public void RefreshFilesList(string directory)
        {
            IList<FileSystemInfo> visibleThings = new List<FileSystemInfo>();
            var dir = new DirectoryInfo(directory);

            try
            {
                foreach (var item in dir.GetFileSystemInfos().Where(item => item.IsVisible()))
                {
                    visibleThings.Add(item);
                }
            }
            catch (Exception ex)
            {
                Log.Error("FileListFragment", "Couldn't access the directory " + _directory.FullName + "; " + ex);
                Toast.MakeText(Activity, "Problem retrieving contents of " + directory, ToastLength.Long).Show();
                return;
            }

            _directory = dir;

            _adapter.AddDirectoryContents(visibleThings);

            // If we don't do this, then the ListView will not update itself when then data set 
            // in the adapter changes. It will appear to the user that nothing has happened.
            ListView.RefreshDrawableState();

            Log.Verbose("FileListFragment", "Displaying the contents of directory {0}.", directory);
        }
开发者ID:BratislavDimitrov,项目名称:monodroid-samples,代码行数:29,代码来源:FileListFragment.cs

示例14: ProcessFiles

        private void ProcessFiles(string strDirectory, string strFileSpec)
        {
            var di = new DirectoryInfo(strDirectory);
            FileSystemInfo[] fis = di.GetFileSystemInfos(strFileSpec);

            // Get all files at this directory level first.
            foreach (FileSystemInfo fi in fis)
            {
                ++this.NumberOfFilesProcessed;
                if (this.Verbose)
                {
                    // From TestRectilinear, so write a blank line before next test method if there's a bunch of output
                    this.WriteLineFunc(string.Empty);
                }
                this.WriteLineFunc(string.Format("( {0} )", fi.FullName));
                ProcessFile(fi.FullName);
            }

            // Now handle recursion into subdirectories.
            if (Recursive)
            {
                // Recurse into subdirectories of this directory for files of the same spec.
                foreach (string strSubdir in Directory.GetDirectories(strDirectory))
                {
                    ProcessFiles(Path.GetFullPath(strSubdir), strFileSpec);
                }
            }
        }
开发者ID:WenzCao,项目名称:automatic-graph-layout,代码行数:28,代码来源:BasicFileProcessor.cs

示例15: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                al.Clear();
                listBox1.Items.Clear();
                txtPicPath.Text = folderBrowserDialog1.SelectedPath;//获取选定的路径
                DirectoryInfo di = new DirectoryInfo(txtPicPath.Text);
                fsinfo = di.GetFileSystemInfos();//返回目录的所有文件

                for (int i = 0; i < fsinfo.Length; i++)
                {
                    string filename = fsinfo[i].ToString();

                    string filetype = filename.Substring(filename.LastIndexOf(".") + 1, filename.Length - filename.LastIndexOf(".") - 1);
                    filetype = filetype.ToLower();//转换为小写
                    if (filetype == "jpg" || filetype == "png" || filetype == "gif" || filetype == "bmp" || filetype == "jpeg")
                    {
                        //将图片放入listbox
                        listBox1.Items.Add(fsinfo[i].ToString());
                        //将图片放入动态数组
                        al.Add(fsinfo[i].ToString());
                        flag++;
                    }
                }
                listBox1.SetSelected(0, true);
                listBox1.Focus();
                tssltotle.Text = "共有" + flag + "张图片";
                Pflag = true;
            }
            //test = txtPicPath.Text.Trim().Length;
            button2.Enabled = true;
        }
开发者ID:xforce-xiang,项目名称:xiangtangongkaike,代码行数:33,代码来源:Form1.cs


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