Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with file copy

Status
Not open for further replies.

Insider1984

Technical User
Feb 15, 2002
132
US
I have the following code setup to copy the first passin to the second. The problem is that the folders need to exsist. I would like it to create the folders if they do not exsist

Basically the program takes a "main" folder with subfolders full of images... renames them and then inside the main folder adds "_new" to the subfolder and places the images inside the folder.

Again currently this doesn't work because the folder needs to exsist the way my code is written currently.

Any help with this would be great.. Thanks!

Code:
int CCompareDlg::FileCopy( const char *src, const char *dst )
{
#define BUFSZ 16000

char            *buf;
FILE            *fi;
FILE            *fo;
unsigned        amount;
unsigned        written;
int             result;

buf = new char[BUFSZ];

fi = fopen( src, "rb" );
fo = fopen( dst, "wb" );

result = COPY_OK;
if  ((fi == NULL) || (fo == NULL) )
  {
  result = COPY_ERROR;
  if (fi != NULL) fclose(fi);
  if (fo != NULL) fclose(fo);
  }

if (result == COPY_OK)
  {
  do
    {
    amount = fread( buf, sizeof(char), BUFSZ, fi );
    if (amount)
      {
      written = fwrite( buf, sizeof(char), amount, fo );
      if (written != amount)
        {
        result = COPY_ERROR; // out of disk space or some other disk err?
        }
      }
    } // when amount read is < BUFSZ, copy is done
  while ((result == COPY_OK) && (amount == BUFSZ));
  fclose(fi);
  fclose(fo);
  }
delete [] buf;
return(result);
}
 
I answered my own question:


Code:
char filename_long_s = filename_long.GetBuffer(0);
BOOL bolly = CreateDirectory(filename_long_s, NULL);



CreateDirectory
The CreateDirectory function creates a new directory. If the underlying file system supports security on files and directories, the function applies a specified security descriptor to the new directory. Note that CreateDirectory does not have a template parameter, while CreateDirectoryEx does.

BOOL CreateDirectory(
LPCTSTR lpPathName, // pointer to directory path string
LPSECURITY_ATTRIBUTES lpSecurityAttributes // pointer to security descriptor
);




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top