473,809 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Tyler Wiebe
66 New Member
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 2669
PsychoCoder
465 Recognized Expert Moderator Contributor
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
Tyler Wiebe
66 New Member
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 Recognized Expert Top Contributor
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
Tyler Wiebe
66 New Member
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
6105
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 Denied". Why am I getting an error like this? How to populate the TreeView with Folders and files of the System?
0
1792
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 project (Active) * Build Installation Project When I try to run the setup.msi, a MessageBox comes up saying "The
1
7223
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? I have looked on Google and have not found an answer.
1
1309
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 shows the user the files that exist in one folder. I want to expand this functionallity so that they can create/delete subfolders and files under thier root folder on the webserver. And perhaps eventually allow the users to create subfolders and...
2
1595
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 you can imagine, this is sometimes a pain in the ... When I go back to working on the computer with VS.Net installed, I copy any newly created files and folders from the live server onto the local machine for further dev work.
6
1410
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 how many subfolders there will be, it can be 1, it can be 3, but it could be 15 to. I don't want to write all these if's and for's in each other and than still be limited with the predefined number of folders that are coded in the for/if structure....
1
4749
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 and folders , and put files into folders , sub folders etc. 2. every object in the cache can be accessed via: name , but also based on some unique ID , for example , the hash of the file data. 3. deleting folder will delete all it's sub folders &...
3
1416
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 include'../addressbook/image_upload.php' ; and add.php has path like addressbook/admin/add.php by doing so i am getting the following error..
1
1376
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 works fine when whole folder including sub folders of "abc" are to be copied into "xyz" folder but i have a index file "index.xls" which contain some folder names and i want to copy only those folders whose names are present in index file i used...
3
2984
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 imported ( require("passes.php") ) at the top of each page. And I have another folder containing other include files like functions. Can you please explain what folder permissions I need to have for each one of these folders in order to prevent...
0
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10643
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10378
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10121
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3862
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.