Was the best way to create path a copy files

  • Thread starter Thread starter William S
  • Start date Start date
W

William S

I know there a few different and probably betters way to accomplish what I'm
doing.

I've got file a network drive, that I want to copy to my local drive, and I
want to keep the same path (UNC) structure.

For instance, I've got ...
z:\parentfolder\subfolder1\subfolder2\file1.txt
z:\parentfolder\subfolder1\subfolder2\file2.txt
z:\parentfolder\subfolder1\subfolder2\file3.txt

and i want to move everything to my local disk so I'll have

c:\parentfolder\subfolder1\subfolder2\file1.txt
c:\parentfolder\subfolder1\subfolder2\file2.txt
c:\parentfolder\subfolder1\subfolder2\file3.txt


I've written code to recursively get the folder names then apending them to
a string, then written another recursive function to create that folder
structure on my local disk, then with a for loop I copy the file from source
to destination.

This seem like a lot of code, and time to me when I think .NET should
provide some easier methods to accomplish such a trivial task. Maybe I'm
missing something.

Thanks for reading
 
I know there a few different and probably betters way to accomplish what I'm
doing.

I've got file a network drive, that I want to copy to my local drive, andI
want to keep the same path (UNC) structure.

For instance, I've got ...
z:\parentfolder\subfolder1\subfolder2\file1.txt
z:\parentfolder\subfolder1\subfolder2\file2.txt
z:\parentfolder\subfolder1\subfolder2\file3.txt

and i want to move everything to my local disk so I'll have

c:\parentfolder\subfolder1\subfolder2\file1.txt
c:\parentfolder\subfolder1\subfolder2\file2.txt
c:\parentfolder\subfolder1\subfolder2\file3.txt

I've written code to recursively get the folder names then apending them to
a string, then written another recursive function to create that folder
structure on my local disk, then with a for loop I copy the file from source
to destination.

This seem like a lot of code, and time to me when I think .NET should
provide some easier methods to accomplish such a trivial task.  Maybe I'm
missing something.

Thanks for reading

It was my impression that a:

Directory.CreateDirectory("c:\parnetfolder\subfolder1\subfolder2");

would create all subfolders if they did not exist.
 
I know there a few different and probably betters way to accomplish what I'm
doing.

I've got file a network drive, that I want to copy to my local drive, andI
want to keep the same path (UNC) structure.

For instance, I've got ...
z:\parentfolder\subfolder1\subfolder2\file1.txt
z:\parentfolder\subfolder1\subfolder2\file2.txt
z:\parentfolder\subfolder1\subfolder2\file3.txt

and i want to move everything to my local disk so I'll have

c:\parentfolder\subfolder1\subfolder2\file1.txt
c:\parentfolder\subfolder1\subfolder2\file2.txt
c:\parentfolder\subfolder1\subfolder2\file3.txt

I've written code to recursively get the folder names then apending them to
a string, then written another recursive function to create that folder
structure on my local disk, then with a for loop I copy the file from source
to destination.

This seem like a lot of code, and time to me when I think .NET should
provide some easier methods to accomplish such a trivial task.  Maybe I'm
missing something.

Thanks for reading

Hi,

You have to do it anyway, going recursive I mean. And if you do not do
it, then somebody else (the framework, the API) will have to do it for
you.

AFAIK there is no a method for that in the framework. Either you do it
(as you did) or maybe you could use xcopy from the OS
 
It was my impression that a:

Directory.CreateDirectory("c:\parnetfolder\subfolder1\subfolder2");

would create all subfolders if they did not exist.

Yes it will
But what about the files???
You still need to recursively navigate the folders to copy the files
 
Yes it will
But what about the files???
You still need to recursively navigate the folders to copy the files

I woudl first generate a list of full path's for each source file.

then loop through the file list.

1. use fileinfo class to get the directory the current file is in, or
a Path method to get it.
2. if the target directory does not exist, create it.
3. copy the file.
 
Thanks for all the tips

I was given a utility that at one point did the same thing I'm trying to
accomplish today, only it was from the DOS era and written in Pascal, and
no longer works. I thought with the .NET framework there would be some
methods that would make it a bit easier, since it seems I'm using the same
philosophy that was used 15-20 years ago.
 
Thanks for all the tips

I was given a utility that at one point did the same thing I'm trying to
accomplish today,  only it was from the DOS era and written in Pascal, and
no longer works.  I thought with the .NET framework there would be some
methods that would make it a bit easier, since it seems I'm using the same
philosophy that was used 15-20 years ago.

If you are looking for a utility. look into rsync.

http://rsync.samba.org/
 
Back
Top