Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 05-05-2005, 08:42 PM   #1 (permalink)
Charmy
Registered User
 
Join Date: May 2005
Posts: 2
Charmy is on a distinguished road
Smile Recursive Directory Listings.

Greetings,

I am hoping someone can help me out here.

Currently i am in the process of creating a program that creates a list of files in a given directory, their size, timestamp, and CRC etc... (its for a updater program...) anyway...

Right now i use this piece of code to generate a directory content listing.
Code from Oslink
Code:
#include <windows.h>
#include <winbase.h>

namespace oslink
{
	class directory
	{
		public:
			directory(const std::string& aName)
				: handle(INVALID_HANDLE_VALUE), willfail(false)
				{
					// First check the attributes trying to access a non-directory with 
					// FindFirstFile takes ages
					DWORD attrs = GetFileAttributes(aName.c_str());
					if ( (attrs == 0xFFFFFFFF) || ((attrs && FILE_ATTRIBUTE_DIRECTORY) == 0) )
					{
						willfail = true;
						return;
					}
					std::string Full(aName);
					// Circumvent a problem in FindFirstFile with c:\\* as parameter 
					if ( (Full.length() > 0) && (Full[Full.length()-1] != '\\') )
						Full += "\\";
					WIN32_FIND_DATA entry;
					handle = FindFirstFile( (Full+"*").c_str(), &entry);
					if (handle == INVALID_HANDLE_VALUE)
						willfail = true;
					else
						current = entry.cFileName;
				}
			~directory()
				{
					if (handle != INVALID_HANDLE_VALUE)
						FindClose(handle);
				}

			operator void*() const				
				{
					return willfail ? (void*)0:(void*)(-1);
				}
			char* next()
				{
					char* prev = current;
					WIN32_FIND_DATA entry;
					int ok = FindNextFile(handle, &entry);
					if (!ok)
						willfail = true;
					else
						current = entry.cFileName;
					return current; 
				}
		private:
			HANDLE	handle;
			bool	willfail;
			char* current;
	};
}
however i will be honest i don't know alot about windows programming, so when i look at alot of this i don't know the windows API well enough to figure out where to change it so that when it finds a directory it will list the files in that directory and the returned string will be like "/directory/file.ext"

In case that didn't make sense here is an example directory structure.
Code:
[Directory1]
--File1.ext
--File2.ext
--[SubDirectory1]
----File3.ext
--[SubDirectory2]
----File4.ext
----File5.ext
--File6.ext
--[SubDirectory3]
----File7.ext
From that i wish to find a way so that my final file listing will be somthing like the following.
Code:
File1.ext
File2.ext
/SubDirectory1/File3.ext
/SubDirectory2/File4.ext
/SubDirectory2/File5.ext
File6.ext
/SubDirectory3/File7.ext
I can assemble the strings and everything later, thats not the issue, I just need the oslink code to return the subdirectory files in the above format (/SubDirectoryX/FileX.ext).

I do so hope that this makes sense, and I really appricate any help you can offer =). If you know of another example of code, or a lib that does this kind of stuff, i am not tied to the oslink one by anymeans.

Thanks again!!!
Charmy is offline   Reply With Quote
Old 05-06-2005, 04:14 AM   #2 (permalink)
Charmy
Registered User
 
Join Date: May 2005
Posts: 2
Charmy is on a distinguished road
Huzzah I figured it out.
Charmy is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
get/change current directory in windows enemite Platform/API C++ 2 04-22-2005 09:36 PM
Get directory files into html links listing Wysocki PHP 1 04-01-2005 10:31 AM
copy a directory link with -Rs sde Linux / BSD / OS X 3 02-15-2005 05:34 PM
reading files from a directory and printing philthee Java 4 10-29-2004 05:01 AM
get the size of a directory and its contents sde Linux / BSD / OS X 6 10-06-2004 04:55 AM


All times are GMT -8. The time now is 05:26 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting