From: Sa3Q on
On 17 نوفمبر, 13:26, "Alf P. Steinbach" <al....(a)start.no> wrote:
> * Sa3Q:
>
> > i use visul c++ version "6"
>
> Don't know if this will compile with MSVC 6.0 (hey, it's time to upgrade!), but
> I translated your mostly-C code to C++.
>
> It's not how I'd done it, but it's a fairly direct translation.
>
> Note how it's shorter, simpler and works:
>
> <code>
> #include <windows.h>
> #include <string>
> #include <fstream>
>
> std::string tabs( int n ) { return std::string( 4*n, ' ' ); }
>
> class XMLFile
> {
> public:
>      XMLFile( std::string const& name );
>
>      void openNewDirectoryLevel( std::string const& name );
>      void closeCurrentDirectoryLevel();
>      void addNewFile( std::string const& name, int size);
>
> private:
>      std::ofstream   m_file;
>      int             m_nTabs;
>
>      XMLFile( XMLFile const& );              // No such.
>      XMLFile& operator=( XMLFile const& );   // No such.
>
> };
>
> XMLFile::XMLFile( std::string const& name )
>      : m_file( name.c_str() )
>      , m_nTabs( 0 )
> {
>      m_file << "<?xml version=\"1.0\"?>\n";
>
> }
>
> void XMLFile::openNewDirectoryLevel( std::string const& name )
> {
>      m_file << tabs( m_nTabs ) << "<directory name=\"" << name << "\">\n";
>      ++m_nTabs;
>
> }
>
> void XMLFile::closeCurrentDirectoryLevel()
> {
>      --m_nTabs;
>      m_file << tabs( m_nTabs ) << "</directory>\n";
>
> }
>
> void XMLFile::addNewFile( std::string const& name, int size )
> {
>      m_file << tabs( m_nTabs ) << "<file name=\"" << name << "\"/>\n";
>
> }
>
> std::string getCurrentDir()
> {
>      int const   length  = GetCurrentDirectory(0, NULL);
>      std::string result  = std::string( length + 1, '\0' );
>
>      GetCurrentDirectory( length + 1, &result[0] );
>      result.resize( length );
>
>      return result;
>
> }
>
> void traverse( XMLFile& out, std::string const& directory )
> {
>      WIN32_FIND_DATA wfd;
>      HANDLE hFind;
>
>      out.openNewDirectoryLevel( directory );
>      hFind = FindFirstFile( (directory + "\\*").c_str(), &wfd );
>      if( hFind != INVALID_HANDLE_VALUE )
>      {
>          do
>          {
>              if( strcmp(wfd.cFileName, ".") && strcmp( wfd.cFileName, ".." ) )
>              {
>                  if( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
>                  {
>                      traverse( out, directory + "\\" + wfd.cFileName );
>                  }
>                  else
>                  {
>                      out.addNewFile( wfd.cFileName, wfd.nFileSizeLow );
>                  }
>              }
>          } while( FindNextFile(hFind, &wfd ) != 0 );
>      }
>      out.closeCurrentDirectoryLevel();
>      FindClose(hFind);
>
> }
>
> int main()
> {
>      XMLFile outc( "d.xml" );
>      traverse( outc, "c:\\test" );}
>
> </code>
>
> Cheers & hth.,
>
> - Alf




this code not run :(
From: Alf P. Steinbach on
* Sa3Q:
>
> this code not run :(

If you want help with that then you'll have to supply the relevant information.


Cheers & hth.,

- Alf
From: Sa3Q on
On 17 نوفمبر, 17:14, "Alf P. Steinbach" <al....(a)start.no> wrote:
> * Sa3Q:
>
>
>
> > this code not run  :(
>
> If you want help with that then you'll have to supply the relevant information.
>
> Cheers & hth.,
>
> - Alf

thank you the code run perfect on msvc 6

i try to compile it on
msvc 9
but it not run
thank you thank you