directory copy

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GS

    #1

    directory copy

    from the online help, looks like to code step by step to copy content of
    directory to another whereas I can use online line code for directory move
    or delete.
    I am using 2005 express .net 2
    I did not any thing(or I did not have the right search term ) for copy
    contents of directory to another and replacing /delete all files in the
    target directory

    Is there an easier way?



  • Ignacio Machin \( .NET/ C# MVP \)

    #2
    Re: directory copy

    Hi,

    I do not remember any clas sin the framework that does it.
    You have two options:
    1- Write a recursive method that copy and recreate the struct (using
    File.Copy & Directory.Creat eDirectory)
    2- use xcopy

    I would recommend the second option.


    --
    Ignacio Machin
    The #1 Warehouse Management System & Direct Store Delivery Software (DSD) for QuickBooks & ERP Systems – LaceUp Solutions

    Mobile & warehouse Solutions.
    "GS" <gsmsnews.micro soft.comGS@msne ws.Nomail.comwr ote in message
    news:%23cWwQtDO IHA.4740@TK2MSF TNGP02.phx.gbl. ..
    from the online help, looks like to code step by step to copy content of
    directory to another whereas I can use online line code for directory move
    or delete.
    I am using 2005 express .net 2
    I did not any thing(or I did not have the right search term ) for copy
    contents of directory to another and replacing /delete all files in the
    target directory
    >
    Is there an easier way?
    >
    >
    >

    Comment

    • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

      #3
      Re: directory copy

      GS wrote:
      from the online help, looks like to code step by step to copy content of
      directory to another whereas I can use online line code for directory move
      or delete.
      I am using 2005 express .net 2
      I did not any thing(or I did not have the right search term ) for copy
      contents of directory to another and replacing /delete all files in the
      target directory
      >
      Is there an easier way?
      For inspiration:

      private void XCopy(string dir1, string dir2)
      {
      string[] files = Directory.GetFi les(dir1);
      foreach (string f in files) {
      File.Copy(f, dir2 + f.Substring(dir 1.Length), true);
      }
      string[] dirs = Directory.GetDi rectories(dir1) ;
      foreach (string d in dirs) {
      XCopy(d, dir2 + d.Substring(dir 1.Length));
      }
      }

      Arne

      Comment

      • gs

        #4
        Re: directory copy

        Thank you. I got it working form your inspiration. I tumbled at the for
        (string sfile in aDir)
        the sfile actually contained the entire file spec including path.
        that was not a big deal once found out what is the culprit. took care of by
        using indexOfRev and substring

        "Arne Vajhøj" <arne@vajhoej.d kwrote in message
        news:475895c8$0 $90274$14726298 @news.sunsite.d k...
        GS wrote:
        >from the online help, looks like to code step by step to copy content of
        >directory to another whereas I can use online line code for directory
        >move
        >or delete.
        >I am using 2005 express .net 2
        >I did not any thing(or I did not have the right search term ) for copy
        >contents of directory to another and replacing /delete all files in the
        >target directory
        >>
        >Is there an easier way?
        >
        For inspiration:
        >
        private void XCopy(string dir1, string dir2)
        {
        string[] files = Directory.GetFi les(dir1);
        foreach (string f in files) {
        File.Copy(f, dir2 + f.Substring(dir 1.Length), true);
        }
        string[] dirs = Directory.GetDi rectories(dir1) ;
        foreach (string d in dirs) {
        XCopy(d, dir2 + d.Substring(dir 1.Length));
        }
        }
        >
        Arne

        Comment

        • gs

          #5
          Re: directory copy

          Actually if I copied you code verbatim and modify from there I could have
          avoided the trouble.

          was not paying attention.

          "Arne Vajhøj" <arne@vajhoej.d kwrote in message
          news:475895c8$0 $90274$14726298 @news.sunsite.d k...
          GS wrote:
          >from the online help, looks like to code step by step to copy content of
          >directory to another whereas I can use online line code for directory
          >move
          >or delete.
          >I am using 2005 express .net 2
          >I did not any thing(or I did not have the right search term ) for copy
          >contents of directory to another and replacing /delete all files in the
          >target directory
          >>
          >Is there an easier way?
          >
          For inspiration:
          >
          private void XCopy(string dir1, string dir2)
          {
          string[] files = Directory.GetFi les(dir1);
          foreach (string f in files) {
          File.Copy(f, dir2 + f.Substring(dir 1.Length), true);
          }
          string[] dirs = Directory.GetDi rectories(dir1) ;
          foreach (string d in dirs) {
          XCopy(d, dir2 + d.Substring(dir 1.Length));
          }
          }
          >
          Arne

          Comment

          Working...