Results 1 to 10 of 10

Thread: Directory Copy **SOLVED**

  1. #1

    Thread Starter
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476

    Question Directory Copy **SOLVED**

    I am really pi**#* , but maybe I just dont understand it correct.

    In dot net there is a Directory.Move Function. There is also a directory.delete method.
    But there is no Directory.Copy Function

    I mean hey, if I have a delete and a copy, I can create my own move Function with these two methods.
    Now I need to write my own copy function, that sucks.

    Sometimes I just dont understand Micro...

    But hey, maybe thats just me and there is a good explanation for that.


    Take care,

    Stephan
    Last edited by Sgt-Peppa; Nov 13th, 2003 at 08:47 AM.
    Keep Smiling - even if its hard
    Frankie Says Relax, wossname Says Yeah!
    wossname:--Currently I'm wearing a gimp suit and a parachute.
    C# - Base64 Blog

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    This is indeeed fascinating. The examples table lists "Copy a directory" and sends the you to Directory overview. Only, there is no example of copying a directory there...

    You could try File.Copy to copy the directory, but I doubt it will succeed.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476
    Heres a class I wrote that does the trick for my Purposes. Maybe someone else is interested in that:

    Code:
    public class CopyDirectory
    	{
    		string source;
    		string destination;
    
    		public CopyDirectory(string mySource, string myDestination)
    		{
    			if(source=="")
    			{
    				throw new Exception("Class CopyDirectory created an Exception, string source has no value!");
    			}
    			if(destination=="")
    			{
    				throw new Exception("Class CopyDirectory created an Exception, string destination has no value!");
    			}
    			source = mySource;
    			destination = myDestination;
    			Directory.CreateDirectory(destination + @"\" + source);
    			CopyThisFolder(source);
    
    		}
    		private void CopyThisFolder(string folder)
    		{
    			string [] items;
    			items = Directory.GetFileSystemEntries(folder);
    			foreach (string item in items)
    			{
    				if (Directory.Exists(item)==true)
    				{
    					Directory.CreateDirectory(destination + @"\" + item);
    					CopyThisFolder(item);
    				}
    				else
    				{
    					string thisFile = item.Substring(item.LastIndexOf(@"\",item.Length,item.Length),item.Length-(item.LastIndexOf(@"\",item.Length,item.Length)));
    					File.Copy(item,destination + @"\" + item, true);
    				}
    			}
    		}
    	}
    Take Care,

    Stephan
    Keep Smiling - even if its hard
    Frankie Says Relax, wossname Says Yeah!
    wossname:--Currently I'm wearing a gimp suit and a parachute.
    C# - Base64 Blog

  4. #4
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    um why not try the DirectoryInfo class?
    It's methods include:
    Create()
    Delete()
    MoveTo()
    CopyTo()

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    CopyTo is not listed in the VS.Net 2003 reference. I already looked.

    Doesn't mean it's not there though.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476
    Originally posted by DeadEyes
    um why not try the DirectoryInfo class?
    It's methods include:
    Create()
    Delete()
    MoveTo()
    CopyTo()
    Have you tried that? Are you sure about that? My Visual Studio does not show that method! All relevant methods I have are :

    CREATE();
    CREATESUBDIRECTORY();
    DELETE();
    MOVETO();

    No Copy method at all.

    I am using NET FRAMEWORK v1.1.4322
    and Visual Studion 2003 English version 7.1.3088

    But maybe I am just to blind to find it


    Thanks all,


    Stephan
    Keep Smiling - even if its hard
    Frankie Says Relax, wossname Says Yeah!
    wossname:--Currently I'm wearing a gimp suit and a parachute.
    C# - Base64 Blog

  7. #7
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    there is no CopyTo() on the directoryinfo , that only exists on fileinfo
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  8. #8

    Thread Starter
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476

    Talking

    Originally posted by dynamic_sysop
    there is no CopyTo() on the directoryinfo , that only exists on fileinfo
    Thanks, thats what I thought!
    Yeah, I am not blind

    But my small class does the trick for me.

    Maybe I should send it to bill and ask him to implement it in the Framework

    Thanks again for all your comments,

    Take care

    Stephan
    Keep Smiling - even if its hard
    Frankie Says Relax, wossname Says Yeah!
    wossname:--Currently I'm wearing a gimp suit and a parachute.
    C# - Base64 Blog

  9. #9
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    Originally posted by dynamic_sysop
    there is no CopyTo() on the directoryinfo , that only exists on fileinfo
    Thanks for the correction. I was looking at a book that was talking about both classes and listed some methods, which I assumed applied to both classes.

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    And damn well they should.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width