Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 09-20-2005, 09:16 PM   #1
Baseband Member
 
Join Date: Aug 2005
Posts: 31
Default file transfer command in c++?

im new to c++ and im wonderin if theres a command that can move a file from one folder to another?
__________________

blink13 is offline   Reply With Quote
Old 09-21-2005, 05:57 PM   #2
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,007
Default Re: file transfer command in c++?

there isn't on, (I don't think)
just open a file for reading, and then open a file for writting, read from one and write to the other... then delete the source file.
__________________

__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 09-28-2005, 12:21 PM   #3
Fully Optimized
 
UK31337's Avatar
 
Join Date: Feb 2005
Posts: 2,776
Default Re: file transfer command in c++?

Quote:
Originally Posted by blink13
im new to c++ and im wonderin if theres a command that can move a file from one folder to another?
The Win32 API has functions to do this within Windows. There are other cross-platform alternatives included in wxWidgets etc., but there is no native C++ function to do it.
__________________
Master of common sense. If you don't like it, stop reading.
UK31337 is offline   Reply With Quote
Old 09-28-2005, 02:31 PM   #4
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,007
Default Re: file transfer command in c++?

you could also detect what sort of system it is, (win32 or unix/linux), then use the system command...

system("move");
system("mv");

depending on the system that is detected
__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 09-30-2005, 04:49 PM   #5
Baseband Member
 
Griz803's Avatar
 
Join Date: Jun 2004
Posts: 89
Default Re: file transfer command in c++?

Well, it's not C++, but here is some old C code that'll probably compile or not depending on your compiler and the available libraries and settings. You'll have to fiddle with it a bit, but it is here.

Code:
#include <stdio.h>
#include <conio2.h>

/*
  These define statements are used in calls to functions later.
 */
#define IN_F_NAME "Test.txt" /* Filename being copied from. */
#define OUT_F_NAME "Copy.txt" /* Filename being copied to. */
#define READ "rt" /* Sets up parameters for a read only text file. */
#define WRITE "wt" /* Sets up parameters for a write only text file. */

void scrhld(void)
{
     /* 
        Prompt the user to press a key to continue the program.
     */
     printf("\t\t\tPress Any Key to Continue...\n");
     
     /* 
        Wait for a key press and discard it.
     */
     getch();
}


FILE * file_open(char * name, const char * params)
{
    
     FILE * cur;
     
     
     if((cur=fopen(name,params)) == NULL)
                               {
                                    
                                     puts("Error Opening File");
                                     
                                     
                                      scrhld();
                                     
                                     
                                     exit(1);
                               } 
     
     return(cur);
}


void make_copy(FILE * cur_in, FILE * cur_out)
{
    
     char temp;
     
    
     while(0 == feof(cur_in))
                  {
                         
                         fscanf(cur_in, "%c1", &temp);               
                         fprintf(cur_out, "%c", temp);
                  }
     
}

void close_files(FILE * cur_in, FILE * cur_out)
{
     
     fflush(cur_in);
     fflush(cur_out);
     fclose(cur_in);
     fclose(cur_out);
     
}



int main(void)
{
   
    FILE * in, * out;
    
    
    in=file_open(IN_F_NAME, READ);
    out=file_open(OUT_F_NAME, WRITE);
    
    make_copy(in, out);
    
    close_files(in, out);
   
    scrhld();    
    
    return 0;
}
Works fine with Dev-C++ as a console project for C. Hope this helps.
__________________
/*What does not kill us, makes us drink far too much caffeine*/
Griz803 is offline   Reply With Quote
Old 10-01-2005, 11:17 AM   #6
Baseband Member
 
Join Date: Aug 2005
Posts: 31
Default

thnx, il try it
__________________

blink13 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 12:32 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0