Loading ...
Sorry, an error occurred while loading the content.

Recursive Directory Copying function

Expand Messages
  • rene_heroux
    Hello. I ve been fiddling with various things to try and create a recursive directory copying function. Needless to say, I can t get it to work correctly. I ve
    Message 1 of 3 , Aug 24, 2003
    • 0 Attachment
      Hello.

      I've been fiddling with various things to try and create a recursive
      directory copying function.

      Needless to say, I can't get it to work correctly.

      I've tried reading the directory into a list, then checking to see
      if the list entry is a directory or not. But that doesn't seem to
      be working.

      Are there any functions for Ocaml out there that already do this?
      If there is, I certainly can't find them, and I've looked around
      quite a bit.

      Any help is appreciated.


      Rene
    • Karl Zilles
      ... Look at the Unix module: The functions stat, lstat, and fstat will let you determine if an entry is a file or directory. Don t let the name fool you, most
      Message 2 of 3 , Aug 24, 2003
      • 0 Attachment
        rene_heroux wrote:
        > I've tried reading the directory into a list, then checking to see
        > if the list entry is a directory or not. But that doesn't seem to
        > be working.
        >
        > Are there any functions for Ocaml out there that already do this?
        > If there is, I certainly can't find them, and I've looked around
        > quite a bit.

        Look at the Unix module:

        The functions stat, lstat, and fstat will let you determine if an entry
        is a file or directory. Don't let the name fool you, most of the
        functions are implemented for windows and macos as well.
      • Stalkern 2
        ... Two useful functions on Unix environment: let is_file name = try ((Unix.stat name).Unix.st_kind = Unix.S_REG) with exn - false ;; let is_dir name = try
        Message 3 of 3 , Aug 25, 2003
        • 0 Attachment
          Il Monday 25 August 2003 07:22, Karl Zilles ha scritto:
          > <html><body>
          >
          >
          > <tt>
          > rene_heroux wrote:<BR>
          > > I've tried reading the directory into a list, then checking to see
          > <BR> > if the list entry is a directory or not.  But that doesn't
          > seem to <BR> > be working.<BR>
          > > <BR>
          > > Are there any functions for Ocaml out there that already do
          > this?  <BR> > If there is, I certainly can't find them, and I've
          > looked around <BR> > quite a bit.<BR>
          > <BR>
          > Look at the Unix module:<BR>
          > <BR>
          > The functions stat, lstat, and fstat will let you determine if an entry
          > <BR> is a file or directory.  Don't let the name fool you, most of the
          > <BR> functions are implemented for windows and macos as well.<BR>
          > <BR>
          > </tt>
          >
          Two useful functions on Unix environment:

          let is_file name = try ((Unix.stat name).Unix.st_kind = Unix.S_REG) with exn
          -> false ;;
          let is_dir name = try ((Unix.stat name).Unix.st_kind = Unix.S_DIR) with exn ->
          false ;;

          For copying, you need a recursive approach for copying directories, and then
          you can copy files as they are, at unchanged depth level.

          To work with this, you could take into consideration a tree, and to keep track
          of your position, your function should have an accumulator. One approach that
          you could follow is to build a filesystem-to-tree function and a
          tree-to-filesystem function, and a function to change the tree root node, i.e
          renaming it. So "Recursive Directory Copying" would consist in:
          1) build the image tree
          2) rename the root node
          3) dump the image tree.

          Of course you don't need to put "real" files into your tree, just their
          positions.

          Ciao
          Ernesto
        Your message has been successfully submitted and would be delivered to recipients shortly.