Guy DeStefano

Using VS 2005, with C++ coding, I am trying to list the entire directory. All is good except, I cannot bypass the directory folder ( C:\System Volume Information ). The XP/2 Op sys lists

1. C:\Support

2. C:\Support\Tools

3. C:\System Volume Information

4. .....

I list all files from C:\ ( want to list until the end of all )

I get:

1. C:\Support

2. C:\Support\Tools

3. C:\

4. It never lists the ( System Volume Information file, and it always goes back to start the entire listing over again, starting from ( C:\ ).

When I try to acces the folder from the XP directory, I get a box stating that it is "Not accessible, Access is denied. Any Suggestions please. Thanks Guy



Re: Visual C++ General listing Dir, will not read C:\System Volume Information

Brendan Grant

Try throwing a try/catch around your work with each directory so that if your work on it fails, you are able to skip on to the next one.




Re: Visual C++ General listing Dir, will not read C:\System Volume Information

Guy DeStefano

Thanks for the suggestion, but I have put in at least 1 million displays. I display each current directory, then sequentially the next directory. It does not stop, or even display anything except when it reaches the prior directory, which is C:\Support\Tools, then the next display is the begining of the file listing, which is directory ( C:\ ), and it continues untill it reaches it again, and the same process, over & over etc.. I have put in hard compares for the file named ( C:\System Volume Information ), but it never sees it, stops, or displays it etc.. The attribs are ( S & H ), and I cannot change them. Any thing else to try Thanks Guy





Re: Visual C++ General listing Dir, will not read C:\System Volume Information

Brendan Grant

You are going to have a problem viewing the contents of System Volume Information, let alone making any changes to it as you likely don¡¯t have permissions to it in the first place, in fact not even an administrator can get in there in the first place... so in order to truly access it... you¡¯d need take ownership by turning off "Hide protected operating system files" and turn on "Show hidden files and folders". Then right-click, Properties, Security, Advanced, Owner, and there you can take ownership and access it.

Otherwise you are going to need to have a way to handle inaccessible folders as chances are it wont be the only one your app encounters, something like this perhaps:

Code Snippet

WalkDirectory(L"C:\\");

...

void WalkDirectory(String ^directory)

{

//Do some (if any) work on/with current directory

try

{

array<String^> ^dirArray = System::IO::Directory::GetDirectories(directory);

System::Collections::IEnumerator^ dirs = dirArray->GetEnumerator();

while ( dirs->MoveNext() )

{

String^ dir = safe_cast<String^>(dirs->Current);

WalkDirectory( dir );

}

}

catch( Exception ^ex)

{

Console::WriteLine("Access Denied: " + directory);

}

}






Re: Visual C++ General listing Dir, will not read C:\System Volume Information

Guy DeStefano

Brendan,

Thank you very much for your help. I have tried to code in the catch, but to be truthful, I have taken an old Microsoft C example, and modified it to include such items as Attributes, times, sizes, totals etc.. I am using the Afxmessage to display items. What you have stated, is what I think I need. I need to be the owner of that directory. I do have the show hidden files on, and the hide extensions turned off. That is why I can see ( via MS ) all the files. I need the statement "Then right-click, Properties, Security, Advanced owner. When I do right-click the properties of the folder ( C:\System Volume Information ), I do not get any thing like you have stated. I just have [General] [Sharing] [Customize].

Some of the code looks like this:

for ( wsA = 0; wsA < 5; wsA++ ) Attribs[wsA] = Space;

if ( Archive ) Attribs[0] = 'A';

if ( Hidden ) Attribs[1] = 'H';

if ( System ) Attribs[2] = 'S';

if ( ReadOnly ) Attribs[3] = 'R';

Attribs[4] = '\0';

FileTimeToSystemTime( &pDW->FindData.ftLastWriteTime, &stLocal );

if ( stLocal.wHour > 4 ) stLocal.wHour = stLocal.wHour - 4;

sprintf_s( DateTime, 64, "%02d/%02d/%d %02d:%02d:%02d:%03d" ,

stLocal.wMonth, stLocal.wDay, stLocal.wYear,

stLocal.wHour, stLocal.wMinute,

stLocal.wSecond, stLocal.wMilliseconds );

wsLen = strlen ( pDW->FindData.cFileName );

strMessage.Format("%s [%s] [%25.25s] ------> [%s]\r\n",

str2, Attribs, DateTime, pDW->FindData.cFileName );

wsLen = strlen( strMessage );

iSize = sprintf_s( prtBuf, ( wsLen + 1 ), "%s", strMessage );

Some of the ouput look like this.

When it hits the folder ( C:\SUPPORT\TOOLS ), The next folder in line according to XP's directory is the folder named ( C:\System Volume Information ). Here is where it acts like it read it and then goes back to ( C:\ ) statrting over again. There are seven directories following, including windows.

====================================================

C:\Program Files\xerox

C:\Program Files\xerox\nwwia

C:\Recycled

C:\RECYCLER

C:\RECYCLER\S-1-5-21-140737819-4230683934-4279755138-500

C:\RECYCLER\S-1-5-21-140737819-4230683934-4279755138-500\Dc448

C:\RECYCLER\S-1-5-21-140737819-4230683934-4279755138-500\Dc455

C:\RECYCLER\S-1-5-21-140737819-4230683934-4279755138-500\Dc460

C:\RECYCLER\S-1-5-21-140737819-4230683934-4279755138-500\Dc461

C:\Sony-Ericsson

C:\SUPPORT

C:\SUPPORT\TOOLS

C:\

C:\$VAULT$.AVG

C:\C#Source

C:\C#Source\AddrBook

C:\C#Source\AddrBook\bin

C:\C#Source\AddrBook\bin\Debug

C:\C#Source\Copy of AddrBook

===========================================================





Re: Visual C++ General listing Dir, will not read C:\System Volume Information

Simple Samples

Guy DeStefano wrote:
Using VS 2005, with C++ coding, I am trying to list the entire directory.

I think you need to be more specific about how you are doing that. What are you using to list the entire directory Since you say later that you are using an old C program as an example, it is nearly certain that the solution is to abandon that solution and use something current. Something like what Brendan Grant provided.






Re: Visual C++ General listing Dir, will not read C:\System Volume Information

Simple Samples

Brendan Grant wrote:

You are going to have a problem viewing the contents of System Volume Information, let alone making any changes to it as you likely don¡¯t have permissions to it in the first place, in fact not even an administrator can get in there in the first place... so in order to truly access it... you¡¯d need take ownership by turning off "Hide protected operating system files" and turn on "Show hidden files and folders". Then right-click, Properties, Security, Advanced, Owner, and there you can take ownership and access it.

A little knowledge can be dangerous and I think this advice is very dangerous. Windows protects that file for a reason and it should not be messed with unless the person knows what they are doing. In this situation, the person neither knows what they are doing nor needs to mess with it. It is not the only file that will cause the problem so it is foolish to mess with all of them.

Brendan Grant wrote:
Otherwise you are going to need to have a way to handle inaccessible folders as chances are it wont be the only one your app encounters, something like this perhaps:

Yes, that is good advice.






Re: Visual C++ General listing Dir, will not read C:\System Volume Information

Guy DeStefano

Problem fixed. In the Microsoft web site, there was an explanation for "File Access Denied". To become the owner of the file, there was a setting to change as an administrator. When the setting was changed, the file was fully accessible. Program works great. Thanks for all the replies.



Re: Visual C++ General listing Dir, will not read C:\System Volume Information

Simple Samples

Guy DeStefano wrote:
Problem fixed. In the Microsoft web site, there was an explanation for "File Access Denied". To become the owner of the file, there was a setting to change as an administrator. When the setting was changed, the file was fully accessible. Program works great. Thanks for all the replies.

That is a dangerous and sloppy solution to your problem.






Re: Visual C++ General listing Dir, will not read C:\System Volume Information

Guy DeStefano

It is used in house only by me. The entire solution stated that this flag may have been turned on during the installation of any number of programs including Anti-Virus, Firewall etc. This happened during the past few months, as I have always been able to look at all files, as any owner of thier own system should be able to do.



Re: Visual C++ General listing Dir, will not read C:\System Volume Information

Simple Samples

There are many files we don't need to look at. The justification here for looking at it is no good. The very excellent reason to not access that data or any other data is because you could then modify something you should not, then you will get a strange error and then ask for help. If you do you will waste people's time, especially yours.

Yes, of course you are entitled to look at the data and mess with it if there is a need to do that. You don't need to for this problem. There are totally valid solutions to your problem. The current solution seems easy now but is the type of solution that can force you to spend a lot of time sometime in the future. As long as I don't spend time trying to help you to fix a problem such as that, then it does not matter to me.






Re: Visual C++ General listing Dir, will not read C:\System Volume Information

Simple Samples

Brendan Grant wrote:
take ownership by turning off "Hide protected operating system files" and turn on "Show hidden files and folders". Then right-click, Properties, Security, Advanced, Owner, and there you can take ownership and access it.

Do you now understand that suggestions such as this should be avoided