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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

system("copy file.txt \s", FileName) doesnt work, any help?

Status
Not open for further replies.

Sherak

Programmer
Sep 1, 2003
83
0
0
GB
Hi,

Im using the system comand to copy a file to another directory however the new dir/file name is specified on runtime, I thought I coudl use the system comand in a similar way to the printf command.. but no joy, any help on this would be appriciated...

thanks
 
Look at FAQ for this forum, esp. faq101-1950 through faq101-1954. I would recommend one of the ShellExecute commands or CreateProcess.

There are also API's and third-party VCL components that will work, too. These work best if you are working with multiple files since they provide the copy animation you see in Windows.

James P. Cottingham
-----------------------------------------
[sup]To determine how long it will take to write and debug a program, take your best estimate, multiply that by two, add one, and convert to the next higher units.[/sup]
 
void ZipBackup (char *targetdir)
{
char *buff1 = new char [256];
char *buff2 = new char [256];

// Check for the backup directory.
if (!DirectoryExists(zipdir))
CreateDir(zipdir);

// Change to the backup directory.
chdir (zipdir);

// Create the command string for the system call to winzip.
if (FileExists ("c:\\windows\\command\\wzzip.exe"))
{
strcpy (buff1, "wzzip -rp ");
ProgressForm->RichEdit1->Lines->Add ("Run winzip command line addon");
}
// Create the command string for the system call to pkzip.
else if (FileExists ("c:\\windows\\command\\zip.exe"))
{
strcpy (buff1, "zip -r ");
ProgressForm->RichEdit1->Lines->Add ("Run PKzip Compression software");
}
else
{
ProgressForm->RichEdit1->Lines->Add ("The compression software could");
ProgressForm->RichEdit1->Lines->Add ("not be found. ");
return;
}

strcat (buff1, "00000.zip ");
strcpy (buff2, targetdir);
path_dos_check (buff2);
strcat (buff1, buff2);
strcat (buff1, "\\");
strcat (buff1, "*.*");

ProgressForm->RichEdit1->Lines->Add ("The files will now be compressed");
ProgressForm->RichEdit1->Lines->Add (buff1);

if (system(buff1) == -1)
ProgressForm->RichEdit1->Lines->Add ("An error occured while compressing the files");

delete buff1;
delete buff2;
}

this example might help

tomcruz.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top