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


C# File.ListFiles方法代码示例

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


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

示例1: DeleteFile

 private void DeleteFile(File dir, string fileName)
 {
     File[] files = dir.ListFiles();
       foreach (File file in files)
       {
     if (fileName.Equals(file.Name))
     {
       file.Delete();
       return;
     }
       }
 }
开发者ID:KennyBu,项目名称:raygun4net,代码行数:12,代码来源:RaygunClient.cs

示例2: deleteAllNotes

        public override void deleteAllNotes()
        {
            try {
                File path = new File(Tomdroid.NOTES_PATH);
                File[] fileList = path.ListFiles(new NotesFilter());

                for(int i = 0; i < fileList.Length-1; i++) {
                    fileList[i].Delete();
                }
            }
            catch (Exception e) {
                TLog.e(TAG, "delete from sd card didn't work");
                SendMessage(NOTE_DELETE_ERROR);
                return;
            }
            TLog.d(TAG, "notes deleted from SD Card");
            SendMessage(REMOTE_NOTES_DELETED);
        }
开发者ID:decriptor,项目名称:tomdroid,代码行数:18,代码来源:SdCardSyncService.cs

示例3: DeleteFolderFile

		/// <summary>
		///  删除指定目录下文件及目录 
		/// </summary>
		/// <param name="filePath">File path.</param>
		/// <param name="deleteThisPath">If set to <c>true</c> delete this path.</param>
		public static void DeleteFolderFile(string filePath,bool deleteThisPath)
		{
			try{
				if (!TextUtils.IsEmpty (filePath)) {
					var file = new File (filePath);
					if (file.IsDirectory) {
						File[] files = file.ListFiles ();
						for (int i = 0; i < files.Length; i++) {
							DeleteFolderFile (files [i].AbsolutePath, true);
						}
					}
					if (deleteThisPath) {
						if (file.IsFile)
							file.Delete ();
						else if (file.IsDirectory)
						if (file.ListFiles ().Length == 0)
							file.Delete ();
					}
				}
			}
			catch(Exception ex) {
				Log.Error (Tag, ex.Message);
			}

		}
开发者ID:lq-ever,项目名称:EldYoungAndroidApp,代码行数:30,代码来源:DeleteCleanCacheManager.cs

示例4: getNotesForSync

        protected override void getNotesForSync(bool push)
        {
            SetSyncProgress(0);

            this.push = push;

            // start loading local notes
            TLog.v(TAG, "Loading local notes");

            File path = new File(Tomdroid.NOTES_PATH);

            if (!path.Exists())
                path.Mkdir();

            TLog.i(TAG, "Path {0} Exists: {1}", path, path.Exists());

            // Check a second time, if not the most likely cause is the volume doesn't exist
            if(!path.Exists()) {
                TLog.w(TAG, "Couldn't create {0}", path);
                SendMessage(NO_SD_CARD);
                SetSyncProgress(100);
                return;
            }

            File[] fileList = path.ListFiles(new NotesFilter());

            if(cancelled) {
                doCancel();
                return;
            }

            // If there are no notes, just start the sync
            if (fileList == null || fileList.Length == 0) {
                TLog.i(TAG, "There are no notes in {0}", path);
                PrepareSyncableNotes(syncableNotes);
                return;
            }

            // get all remote notes for sync

            // every but the last note
            for(int i = 0; i < fileList.Length-1; i++) {
                if(cancelled) {
                    doCancel();
                    return;
                }
                // TODO better progress reporting from within the workers

                // give a filename to a thread and ask to parse it
                SyncInThread(new Worker(fileList[i], false, push));
            }

            if(cancelled) {
                doCancel();
                return;
            }

            // last task, warn it so it will know to start sync
            SyncInThread(new Worker(fileList[fileList.Length-1], true, push));
        }
开发者ID:decriptor,项目名称:tomdroid,代码行数:60,代码来源:SdCardSyncService.cs

示例5: GetFolderSize

		/// <summary>
		/// 获取缓存大小.
		/// </summary>
		/// <returns>The folder size.</returns>
		/// <param name="file">File.</param>
		public static long GetFolderSize(File file)
		{
			long size = 0;
			try{
				File [] fileList = file.ListFiles();
				for(int i=0;i<fileList.Length;i++)
				{
					if(fileList[i].IsDirectory)
						size += GetFolderSize(fileList[i]);
					else
						size += fileList[i].Length();
				}
			}
			catch(Exception ex) {
				Log.Debug (Tag, ex.Message);
			}
			return size;
		}
开发者ID:lq-ever,项目名称:EldYoungAndroidApp,代码行数:23,代码来源:DeleteCleanCacheManager.cs


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