Tag: 目录

如何确定文件夹是否已完成复制c#

我有一个问题:如何确定文件夹是否已从一个位置复制到另一个位置? 目前,我的FileSystemWatcher会在复制目录中的文件后立即触发多个事件。 我想要的是,当成功复制该文件夹中的所有文件时,将触发一个单一事件。 我的代码现在看起来像这样: static void Main(string[] args) { String path = @”D:\Music”; FileSystemWatcher mWatcher = new FileSystemWatcher(); mWatcher.Path = path; mWatcher.NotifyFilter = NotifyFilters.LastAccess; mWatcher.NotifyFilter = mWatcher.NotifyFilter | NotifyFilters.LastWrite; mWatcher.NotifyFilter = mWatcher.NotifyFilter | NotifyFilters.DirectoryName; mWatcher.IncludeSubdirectories = true; mWatcher.Created += new FileSystemEventHandler(mLastChange); mWatcher.Changed += new FileSystemEventHandler(mLastChange); mWatcher.EnableRaisingEvents = true; Console.WriteLine(“Watching path: ” + path); String exit; […]

问题:在运行我的应用程序时使用Windows 7,未经授权的访问exception

我的应用程序引发了未经授权的访问错误 在运行我的应用程序时,我尝试访问以下位置中的目录:Application.UserAppDataPath。 问题:它表示我没有访问Application.UserAppDataPath目录的权限 有没有办法在我的应用程序源代码中设置权限? 就像是: Application.UserAppDataPath.SetPermissions()

如何从目录中获取子文件夹中的文件

嗨,我必须从目录中的指定路径获取文件。 这是我写的方法,但我没有从子文件夹中获取文件。 Private void getfiles(){ Directoryinfo info = new Directoryinfo(configurationmanager.appsettings[“Targetroot”].tostring ()); if (info.exists){ Gvfiles.datasource = info.GetFiles(); Gvfiles.databind(); } }

DirectoryInfo.GetFiles,如何在C#中获取不同类型的文件

如何在C#中使用DirectoryInfo.GetFiles函数找到文件类型* .gif和* .jpg? 当我尝试这段代码时: string pattern = “*.gif|*.jpg”; FileInfo[] files = dir.GetFiles(pattern); 例外“路径中的非法字符”。 被抛出。

如何使用具有特定子目录的通配符扫描目录

我想知道什么是扫描具有您不确定的字符的目录的好方法。 例如,我想扫描 C:\程序\版本2 * \文件 含义 该文件夹位于C:\Program Version2.*可以是Version2.33 , Version2.1等。 该文件夹中有一个名为Files的文件夹 我知道foreach (directory) if contains(“Version2.”) ,我可以做像foreach (directory) if contains(“Version2.”)这样的事情,但我想知道是否有更好的方法。

第二个路径片段不能是驱动器或UNC名称 – 创建子目录错误

我在这段代码的第三行有一个例外“第二个路径片段不能是驱动器或UNC名称” DirectoryInfo labdi = new DirectoryInfo(Back.mainfolderpath + @”\news\l”); DirectoryInfo tld = new DirectoryInfo(labdi.FullName + @”\” + NorA.sn.labl[i]); tld = labdi.CreateSubdirectory(labdi.FullName + @”\” + NorA.sn.labl[i] + @”\”); 网上没有任何有用的方法。 谢谢。:!

在C#中仅列出子文件夹?

我有一些代码: string pathUser = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); string pathDownload = Path.Combine(pathUser, @”documents\iracing\setups\”); DirectoryInfo dinfo = new DirectoryInfo(pathDownload); // Populates field with all Sub Folders FileInfo[] Files = dinfo.GetFiles(“*.sto”); foreach (FileInfo file in Files) { listBox2.Items.Add(file.Name); } 我想要显示: documents\iracing\setups\的子文件夹,而不是文件……包括.sto文件。 我只需要列出子文件夹….我不知道该怎么做? 谢谢!

Directory.GetFiles()不使用“。”模式。

当我将以下行添加到我的WPF应用程序中时,我有一些奇怪的问题。 private void button1_Click(object sender, RoutedEventArgs e) { foreach(string files in Directory.GetFiles(path,”.”,SearchOption.TopDirectoryOnly)) tb_FileBrowse.Text = files; } 问题是在FrameWork 3.5中 ,上面的方法什么都不做,甚至没有错误,但是如果我将它改为FrameWork 4.5就可以了! 此外,如果我使用Framework 3.5并将其更改为ConsolApp,就像这样 foreach (string files in Directory.GetFiles(path, “.”, SearchOption.TopDirectoryOnly)) { Console.WriteLine(“{0}”,files); } 代码给出了一些结果。 有没有人有同样的问题?

区分大小写的Directory.Exists / File.Exists

有没有办法让案例敏感的Directory.Exists / File.Exists从那以后 Directory.Exists(folderPath) 和 Directory.Exists(folderPath.ToLower()) 两者都回归true ? 大多数时候它并不重要但我使用的宏如果路径与100%的情况不匹配似乎不起作用。

C#中的UWP递归文件搜索速度非常慢

我使用以下代码以递归方式搜索所选文件夹中的图像。 我在该文件夹中有超过120000张图像(是的,我是一名摄影师!)而且它非常慢,例如我必须在10分钟后停止它并且还没有完成。 相比之下,我的Python代码(解释!)在不到2分钟内完成相同的操作。 有没有办法让这个代码更有效率? 它工作正常,没关系,但只是非常缓慢…… public List _allFiles; public List ShuffledFiles; public int i = 0; public int ri = 0; public Boolean random = false; public int numfiles = 0; //Get the starting folder for recursive search private static async Task SelectFolderAsync() { var folderPicker = new Windows.Storage.Pickers.FolderPicker { SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop }; //Selects […]