PC Review


Reply
Thread Tools Rate Thread

Was the best way to create path a copy files

 
 
William S
Guest
Posts: n/a
 
      22nd Apr 2009
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


 
Reply With Quote
 
 
 
 
joecool1969@live.com
Guest
Posts: n/a
 
      22nd Apr 2009
On Apr 22, 3:06*pm, "William S" <nos...@spam.com> wrote:
> 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.
 
Reply With Quote
 
Ignacio Machin ( .NET/ C# MVP )
Guest
Posts: n/a
 
      22nd Apr 2009
On Apr 22, 3:06*pm, "William S" <nos...@spam.com> wrote:
> 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
 
Reply With Quote
 
Ignacio Machin ( .NET/ C# MVP )
Guest
Posts: n/a
 
      22nd Apr 2009
On Apr 22, 3:19*pm, joecool1...@live.com wrote:
> On Apr 22, 3:06*pm, "William S" <nos...@spam.com> wrote:
>
>
>
> > 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. *MaybeI'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.


Yes it will
But what about the files???
You still need to recursively navigate the folders to copy the files
 
Reply With Quote
 
joecool1969@live.com
Guest
Posts: n/a
 
      22nd Apr 2009
On Apr 22, 3:43*pm, "Ignacio Machin ( .NET/ C# MVP )"
<ignacio.mac...@gmail.com> wrote:
> On Apr 22, 3:19*pm, joecool1...@live.com wrote:
>
>
>
>
>
> > On Apr 22, 3:06*pm, "William S" <nos...@spam.com> wrote:

>
> > > 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 fromsource
> > > 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.

>
> 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.
 
Reply With Quote
 
joecool1969@live.com
Guest
Posts: n/a
 
      22nd Apr 2009
On Apr 22, 4:09*pm, joecool1...@live.com wrote:
> On Apr 22, 3:43*pm, "Ignacio Machin ( .NET/ C# MVP )"
>
>
>
>
>
> <ignacio.mac...@gmail.com> wrote:
> > On Apr 22, 3:19*pm, joecool1...@live.com wrote:

>
> > > On Apr 22, 3:06*pm, "William S" <nos...@spam.com> wrote:

>
> > > > I know there a few different and probably betters way to accomplishwhat 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 apendingthem 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.

>
> > 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.


Of course,the easist way to do that would be using recursion.

>
> 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.


 
Reply With Quote
 
William S
Guest
Posts: n/a
 
      23rd Apr 2009
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.



"William S" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>



 
Reply With Quote
 
Dude
Guest
Posts: n/a
 
      23rd Apr 2009
On Apr 23, 9:44*am, "William S" <nos...@spam.com> wrote:
> 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.
>
> "William S" <nos...@spam.com> wrote in message
>
> news:(E-Mail Removed)...
>
> >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. *MaybeI'm
> > missing something.

>
> > Thanks for reading


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

http://rsync.samba.org/
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
http://LongPathTool.com - find and delete/copy path too long filesfrom your hard drive or LAN Windows tool to copy or delete files and folderswith path too long or filename too long error. Just browse to the file andpress a button to copy or d Martin Krag Windows XP Internet Explorer 0 22nd Apr 2011 10:08 AM
http://LongPathTool.com - find and delete/copy path too long filesfrom your hard drive or LAN Windows tool to copy or delete files and folderswith path too long or filename too long error. Just browse to the file andpress a button to copy or d Martin Krag Windows XP Networking 0 22nd Apr 2011 10:07 AM
http://LongPathTool.com - find and delete/copy path too long filesfrom your hard drive or LAN Windows tool to copy or delete files and folderswith path too long or filename too long error. Just browse to the file andpress a button to copy or d Martin Krag Windows XP Setup 0 22nd Apr 2011 10:06 AM
http://LongPathTool.com - find and delete/copy path too long filesfrom your hard drive or LAN Windows tool to copy or delete files and folderswith path too long or filename too long error. Just browse to the file andpress a button to copy or d Martin Krag Windows XP Configuration 0 22nd Apr 2011 10:05 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:27 AM.