Tuesday - June 20th 7:30PM - C/C++ Group, SPRS
We will be discussing a program by Joey Rogers in this month's
C/C++ Users Journal: Copying Files from the Clipboard to a
Command Prompt. You can make DOS more of a first-class Windows
citizen with this handy little clipboard utility. I wanted to
be able to copy files from Windows Explorer to the Command
Prompt's active directory via the Windows clipboard. This
article provides a very simple utility, CBcopy, that will
paste files copied onto the Windows clipboard into a
Command Prompt's active directory. CBcopy works by
opening the Windows clipboard and querying for a drop file handle
(CF_HDROP), which points to a list of files currently on the
clipboard. The functions OpenClipboard, GetClipboardData,
GetCurrentDirectory, Global Lock, DragoueryFile, GlobalUnlock,
and CloseClipboard are Win32-specific APIs.) For more info
on the group see their home page or contact Bruce Arnold (908) 735-7898.
SAMPLE CODE
===========
void ProcessDirectory( char *file )
{
// Make new subdirectory if necessary
char newDirectory[_MAX_PATH];
strcpy(newDirectory,destPath);
strcat(newDirectory,&file[basePathSize-1]);
if (noCopyFlag==0)
{
long stat=GetFileAttributes( newDirectory);
if (stat==0xFFFFFFFF)
{
if (_mkdir(newDirectory)==-1)
{
cout << "Unable to create directory: " << newDirectory << endl;
errorCount++;
return;
}
}
}
// Go through all of the files in the subdirectory
struct _finddata_t c_file;
long hFile;
char searchPath[_MAX_PATH], newFile[_MAX_PATH];
sprintf(searchPath,"%s\\*.*",file); // search for all files in dir
if ((hFile = _findfirst( searchPath, &c_file ))!=-1L)
{
if (strcmp(c_file.name,".")!=0 &&
strcmp(c_file.name,"..")!=0)
{
sprintf(newFile,"%s\\%s",file,c_file.name);
ProcessFile( newFile);
}
}
if (hFile!=-1)
{
while (_findnext(hFile,&c_file)==0)
{
if (strcmp(c_file.name,".")!=0 &&
strcmp(c_file.name,"..")!=0)
{
sprintf(newFile,"%s\\%s",file,c_file.name);
ProcessFile( newFile );
}
}
_findclose(hFile);
}
}