New Posts  All Forums:Forum Nav:

Two quick C++ questions

post #1 of 3
Thread Starter 
Question 1: How do I make a C++ program run another file? (such as a batch file or an executable).

Question 2: How do I code a C++ program to manipulate existing files and folders? (move, copy, rename, delete, etc).
post #2 of 3
Thread Starter 
^Bump
post #3 of 3
1) The most basic way to run an executable is

Code:
system("executable.exe");
but that kind of sucks. Basically C++ is powerful in many ways, but not very useful when it comes to threads or applications (and file handling is tricky, as well!) the system() function will basically pause you're entire program until the executable called is completed. Maybe thats allright with what you're doing, maybe not. Its also quite touchy with the file path. The best way to deal with it is just have whatever it is you're executing in the working directory. My advice? Don't use C++


2)
For Copy, use this Link. It sucks that C++ doesn't have a built in file copier, but like I said before, it doesn't take to file handling to nicely.

//RENAME
Code:
int result;
  char oldname[] ="oldname.txt";
  char newname[] ="newname.txt";
 result= rename( oldname , newname );
  if ( result == 0 )
    puts ( "File successfully renamed" );
  else
    perror( "Error renaming file" );
  return 0;
//REMOVE
Code:
  if( remove( "myfile.txt" ) != 0 )
    perror( "Error deleting file" );
  else
    puts( "File successfully deleted" );
  return 0;
It's about time!
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 @3.3Ghz Gigabyte EP45-UD3P Sapphire 2900Pro Flashed to XT 4Gb Gskill 1066Mhz PK's 
Hard DriveOptical DriveOSMonitor
Seagate Barracuda 320Gb & WD Black 640Gb Lite On Vista Business and VMWare Ubuntu Acer AL2223W 22" 
KeyboardPowerCaseMouse
Ergonomic 4000 Corsair HX 620W CM 690 G5 
  hide details  
Reply
It's about time!
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 @3.3Ghz Gigabyte EP45-UD3P Sapphire 2900Pro Flashed to XT 4Gb Gskill 1066Mhz PK's 
Hard DriveOptical DriveOSMonitor
Seagate Barracuda 320Gb & WD Black 640Gb Lite On Vista Business and VMWare Ubuntu Acer AL2223W 22" 
KeyboardPowerCaseMouse
Ergonomic 4000 Corsair HX 620W CM 690 G5 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming