Hirarchical path file copying

This is a discussion on Hirarchical path file copying within the C Programming forums, part of the General Programming Boards category; Hi all, I want to build a hirarchical path for copying a file. Means .. file in source dir is ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    8

    Lightbulb Hirarchical path file copying

    Hi all,

    I want to build a hirarchical path for copying a file. Means ..

    file in source dir is : "./../t/t1/myfile"
    and
    Destination dir is: "./../t/t2/"

    Now, I want to copy myfile from t1 directory to destination directory t2.

    How strrchr() will help me?
    how do I do with that?
    Any suggestion please??


    Really appreaciate.

    Palku

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    strrchr() can return the position of the last slash in your filename. Add one to that, and you have the filename.

    Something like
    Code:
    const char *from = "./../t/t1/myfile", *to = "./../t/t2/";
    char *p, call[1000];
    
    p = strrchr(from, '/')+1;
    
    strcpy(call, "copy ");
    strcat(call, from);
    strcat(call, " ");
    strcat(call, to);
    strcat(call, p);
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 09:47 AM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  4. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21