Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / July 2007

Tip: Looking for answers? Try searching our database.

Create folderstructure based on file.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
iCodeSharp@gmail.com - 31 Jul 2007 09:50 GMT
Hi,

I am struggling with the following issue, i need to copy files from
one place to another...well that isn't so hard..but i also need to
create the folder(s) in which the file orginaly was located. I have a
listbox from where the user can select the files he or she wants to
copy.

So it could be that while there are more then one file in a particular
folder the user only selects one..so i cannot copy the intire
directory and al its subfolders.

Any one got any idea?

Tnx!
Martijn
Karthik D V - 31 Jul 2007 11:09 GMT
Hey state your problem with more clarity...so that we can help you!

iCodeSh...@gmail.com wrote:
> Hi,
>
[quoted text clipped - 12 lines]
> Tnx!
> Martijn
iCodeSharp@gmail.com - 31 Jul 2007 12:07 GMT
> Hey state your problem with more clarity...so that we can help you!
>
[quoted text clipped - 17 lines]
>
> - Show quoted text -

This piece of code is to explain my problem. The code will create this
folder structure in the folder "Test"
Digibox
  _Documentation
    _Test
      D

but i want it to be
D
 _Test
   _Documentation
     Digibox

folderstructure based on FileInfo.FullName

       /// <summary>
       ///
       /// </summary>
       /// <param name="sender"></param>
       /// <param name="e"></param>
       private void button2_Click(object sender, EventArgs e)
       {
           CopyDirectory(@"D:\_Test\_Documentatie\DigiBox
\Werkverslag.doc", @"D:\Test");
       }
       /// <summary>
       ///
       /// </summary>
       /// <param name="_src"></param>
       /// <param name="_dst"></param>
       private void CopyDirectory(string _src, string _dst)
       {
           FileInfo _file = new FileInfo(_src);
           DirectoryInfo _dir = new
DirectoryInfo(_file.Directory.FullName);
           DirectoryInfo _dest = new DirectoryInfo(_dst);
           GetDirStructure(_dir, _dest);
       }
       /// <summary>
       ///
       /// </summary>
       /// <param name="_dirstrc"></param>
       /// <param name="_dest"></param>
       private void GetDirStructure(DirectoryInfo _dirstrc,
DirectoryInfo _dest)
       {
           if (_dirstrc.Parent != null)
           {
               if (_dest.Exists)
                   if (_regex.IsMatch(_dirstrc.Parent.Name) == true)
                   {

_dest.CreateSubdirectory(_regex.Match(_dirstrc.Parent.Name).Result("$
{drive}"));
                   }
                   else
                   {
                       _dest =
_dest.CreateSubdirectory(_dirstrc.Parent.Name);
                   }
               GetDirStructure(_dirstrc.Parent, _dest);
           }
       }
iCodeSharp@gmail.com - 31 Jul 2007 12:48 GMT
On 31 Jul, 13:07, iCodeSh...@gmail.com wrote:

> > Hey state your problem with more clarity...so that we can help you!
>
[quoted text clipped - 83 lines]
>
> - Show quoted text -

This seems to help my me...totally different approach but it works

           string filename = @"D:\_Test\_Documentatie\DigiBox\";
           string drive = _regex.Match(filename).Result("${drive}");
           string folderstr =
filename.Substring(filename.IndexOf(@"\"), filename.Length - 2);

           if(!Directory.Exists(@"D:\_Test\" + drive + "\\" +
folderstr))
           Directory.CreateDirectory(@"D:\_Test\" + drive + "\\" +
folderstr);

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.