directories and files 
Author Message
 directories and files

Hello,
  I need to write a simple application that will take a text file as input,
parse the file and act only on lines that contain a certain keyword.  My
knowledge of C is limited to what I learned in college a few years ago. but
I have the file opening and parsing working.  The lines I need to process
are file names with full path like this:

Source=C:\Program Files\MyApp\bin\app.exe

I can open the file, loop through the lines and pick out the ones that begin
with Source= and even strip the Source= from the line so I am left with just
the path info.  I need to copy these files to a different root path while
maintaining the path structure of the source files.  Like this

c:\program files\myapp\bin\app.exe

gets copied to

c:\newroot\program files\myapp\bin\app.exe.

I need to create the path structure if it is not present under the newroot
folder.  Now the question:

How do I create directories and copy files with long file names in VC++?

Thanks for any help provided.

Olan Wilson



Tue, 14 Oct 2003 00:26:53 GMT  
 directories and files

Quote:
>How do I create directories and copy files with long file names in VC++?

Olan,

Have a look primarily at SHFileOperation - I think that's going to be
the most useful function for your situation. Additionally, there's the
following functions:

        CreateDirectory, _splitpath, _makepath, CopyFile

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Tue, 14 Oct 2003 00:51:27 GMT  
 directories and files

Quote:
> How do I create directories and copy files with long file names in VC++?

The following routine should get you going

 unsigned long create_dir (const std::string& dir)
 {
  // create modifiable copy of target directory
  std::string partial (dir);

  // holds path portions
  std::vector<std::string> v;

  // split the path into portions
  std::string::size_type idx;
  while ((idx = partial.rfind ('\\')) != std::string::npos)
  {
   v.push_back (partial.substr (idx));
   partial.resize (idx);
  }

  // save the drive
  v.push_back (partial);

  // clear partial
  partial.erase ();

  unsigned long rc = NO_ERROR;
  while (rc == NO_ERROR && v.size ())
  {
   // append first/next partial
   partial += v.back ();
   if (::CreateDirectory (partial.c_str (), 0) == 0)
   {
    // if it already exists (includes file)
    if (::GetLastError () == ERROR_ALREADY_EXISTS)
    {
     // There is no error
     rc = NO_ERROR;
    }
    else
    {
     // any other error means we can't create the dir
     rc = CANNOT_CREATE;
    }
   }
   v.pop_back ();
  }
  return rc;
 }



Tue, 14 Oct 2003 04:37:27 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Removing BIN & OBJ Directories - PDB File Error

2. How do action wih Directory and Files ?

3. Deleting directories with files?

4. Getting Directory and File Lists

5. Deleting directories with files?

6. Directories and Files

7. I want to find a ActiveX control that can browse all directory and file in system

8. Find Drives, Directories, and Files

9. Recursively deleting directories and files

10. Is filename directory or file?

11. Is filename directory or file?

12. Separating directory from file specification

 

 
Powered by phpBB® Forum Software