Find the answer to your Linux question:
Results 1 to 4 of 4
Guys, I'm investigating how to copy a file located in my file system into another device. I googled to find a solution for my case but I didn't find anything. ...
  1. #1
    Just Joined! s1rUK's Avatar
    Join Date
    Jun 2010
    Location
    Milan
    Posts
    5

    Question How to interact with the file system by own C source-code

    Guys,

    I'm investigating how to copy a file located in my file system into another device. I googled to find a solution for my case but I didn't find anything. My original problem was to find a way to permit my code to move a file into a USB device.

    I wonder If is there a way to implement the cp command or some mechanism that permits my code to interact with between the file system on my computer and the second one on USB external driver (FAT32) ???

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Execute "bin/cp" with the "system" command.
    Debian GNU/Linux -- You know you want it.

  3. #3
    Linux User
    Join Date
    Jan 2006
    Posts
    414
    Alternatively:
    1. open source file in read mode
    2. open destination file in write mode
    3. copy data over
    4. close files

  4. #4
    Just Joined!
    Join Date
    Jun 2010
    Posts
    10

    systemcall

    As USB flash drives mount as files on the local filesystem, (in my distro, in /media/) you can treat them as a local file (everything is a file in unix).
    The system will treat this as a no brainer local file copy. you could call system("cp /media/myusbdrive/myfile.foo ~/myfilecopy.foo");

    for example at its most basic, you use this within a c program like so:
    Code:
    #include <stdlib.h>
    
    int main(void)
    {
    	system("cp /media/myusbdrive/myfile.foo ~/myfilecopy.foo");
    	
    	return 0;
    }
    Last edited by kingluke; 06-16-2010 at 09:32 PM. Reason: clarity

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...