473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Get Files from folder and sub folders that contains a restricted folder or file.

Tyler Wiebe
Okay, I need to get every audio file on a hard drive, and move them to a single location sorted by the first letter of the artists name, artists name, album, and song title.

I have the code to do that, and it worked on one of the hard drives I'm organizing files from, but the other two contain secured folders and files, and I get an exception when I try and get access to them, and my program justs stops and won't continue.

I'm using something like the following
Expand|Select|Wrap|Line Numbers
  1.         public System.Collections.Generic.List<string> GetFiles(string StartingDirectory)
  2.         {
  3.             System.Collections.Generic.List<string> Extensions = new System.Collections.Generic.List<string>();
  4.             Extensions.Add("mp3");
  5.             //More Extensions
  6.  
  7.             System.Collections.Generic.List<string> Files = new System.Collections.Generic.List<string>();
  8.             foreach (string Extension in Extensions)
  9.             {
  10.                 foreach (string File in System.IO.Directory.GetFiles(StartingDirectory, "*." + Extension, System.IO.SearchOption.AllDirectories)) Files.Add(File);
  11.             }
  12.             return Files;
  13.         }
  14.  
Any help would be appreciated, and sooner the better.
Feb 16 '12 #1
4 2655
PsychoCoder
465 Expert Mod 256MB
You could run the application in admin mode (not sure that would help though) other than that I cannot think of a way since the Windows installation has restricted folders & files that aren't accessible (for security purposes)
Feb 16 '12 #2
Thank you, I'm assuming it worked since it's actually running longer then 1 second. I'm still going through all the files, but it's moved about 250 files that it wasn't before.

Thanks you again.
Feb 16 '12 #3
GaryTexmo
1,501 Expert 1GB
Another option you might want to consider is catching your exceptions. In general, code that can generate exceptions should be placed within a try/catch block. This block can surround any code you wish, so there would be nothing stopping you from doing something like...

Expand|Select|Wrap|Line Numbers
  1. foreach (string folder in foldersToProcess)
  2. {
  3.   try
  4.   {
  5.     // Do whatever...
  6.   }
  7.   catch (Exception exception)
  8.   {
  9.     someLog.AddMessage(string.Format("Could not process folder, '{0}', reason: {1}", folder, exception.Message));
  10.   }
  11. }
That might help your program recover more gracefully from exceptions :)
Feb 16 '12 #4
Okay, I hadn't had a chance to reply yet, but it turns out that giving it administrator privileges doesn't help, the only reason it was working for a bit was because I accidentally set it to search only the top directory and not all of the directories.
Feb 17 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Karuppasamy | last post by:
Hi I want to populate all the files and folders of System in a Treeview control like Windows Explorer. I try this using File System Objects. But sometimes I am getting an error like 'Access...
0
by: muesliflakes | last post by:
I have tried to build an Installation Project for to different applications. Both are simple. Steps Taken: * Add New Setup Project to the solution * Set the project out to the application...
1
by: Keith Smith | last post by:
When I create a setup file (MSI) for my app, I get the following error when I try to run the MSI file... The folder path '.' contains an invalid character Does anyone know a solution to this? ...
1
by: Nut Cracker | last post by:
Hello, If anyone can point me to a good ASP based Control Panel for IIS5, I would be much obliged. I hacked together an ASP site for file uploads and sharing. Its very simple, and basically...
2
by: Jon Maz | last post by:
Hi All, I'm in a possibly unusual situation, that is working alternately on an ASP.NET web site from two dev computers, one of which has VS.Net installed on it, the other of which does not. As...
6
by: Joris De Groote | last post by:
Hi, I have a program that must look in in certain folder and take out every file (also the files in subfolders). Now it's no problem to do this with a few for's and if's. However, I don't know...
1
by: semedao | last post by:
Hi all, I'm looking for some example , open source etc code that implement caching of files and folders with those requirments: 1. like every file system , I can write , read , delete etc files...
3
by: mishrarajesh44 | last post by:
hii all, is it not possible to include a file which is outside the folder which contains the script file(where include( ) is used). my problem is: the file add.php uses the ...
1
by: veer | last post by:
hi it looks a silly question but i m getting confused actually i want to copy folders from one location to another like from C:\abc To D:\xyz here abc and xyz are two folders in c and d drive it...
3
by: bnashenas1984 | last post by:
Hi everyone Can anyone tell me what folder permission I should have for the folder containing MySQL passwords. I have a directory which contains a PHP file with MySQL password. This file gets...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.