Results 1 to 5 of 5

Thread: [RESOLVED] File.Copy() and other backuping information

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Location
    New York
    Posts
    94

    Resolved [RESOLVED] File.Copy() and other backuping information

    I have the person locate files on the harddrive using the dialog boxes located in the SDK, however I have a problem. I add them to listboxes then use for...next loops to iterate through the lists, copying and pasting the files. Unfortunately, so far all attempts at that last part of drudged up nothing but exceptions inolving the existance of the file. I'm kinda stuck and the program is for a small business that a family member owns, so any help would be greatly apprectiated.
    AZURE
    Act 1: Ruby
    Act 2: Cavara Militari
    Act 3:
    Act 4:
    Act 5: Cogito ergo sum

  2. #2
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: File.Copy() and other backuping information

    Are they populating the listbox properly? can you post some code where your exception throws?

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Location
    New York
    Posts
    94

    Re: File.Copy() and other backuping information

    IMPORTANT NOTE: I haven't added support for backing up folders and am not testing it.
    VC#.net 2003

    "System.IO.Exception

    Target directory already exists"

    I did put true in the file.copy method.

    lstCopyFiles is the listbox that saves the file paths. lstDestination is the chance for multiple backups to be created. First block of code is what saves the path.
    VB Code:
    1. private void AddDeterminate(bool AddFile)
    2.         {
    3.             string FileName = "";
    4.             if(AddFile == true)
    5.             {
    6.                 diaFiles.ReadOnlyChecked = true;
    7.                 diaFiles.Multiselect = true;
    8.                 diaFiles.InitialDirectory = "C:";
    9.                 diaFiles.CheckFileExists = true;
    10.                 diaFiles.CheckPathExists = true;
    11.                 diaFiles.Title = "Specify files to be backed up";
    12.                 diaFiles.ShowDialog(this);
    13.                 FileName = diaFiles.FileName.ToString();
    14.             }
    15.             else
    16.             {
    17.                 diaFolder.Description = "Specify folders to be backed up";
    18.                 diaFolder.ShowDialog(this);
    19.                 FileName = diaFolder.SelectedPath.ToString();
    20.             }
    21.             SaveUpdate = false;
    22.             lstCopyFiles.Items.Add(FileName);
    23.         }
    And this is the exception throwing code:
    VB Code:
    1. private void BackUp()
    2.         {
    3.             lstDestination.SelectedIndex = 0;
    4.             int iCount;
    5.             int iCount2;
    6.             for(iCount = 0; iCount < lstCopyFiles.Items.Count;++iCount)
    7.             {
    8.                 for(iCount2 = 0; iCount2 < lstDestination.Items.Count; ++iCount2)
    9.                 {
    10.                     lstCopyFiles.SelectedIndex = 0;
    11.                     File.Copy(lstCopyFiles.SelectedItem.ToString(), lstDestination.SelectedItem.ToString(),true);
    12.                 }
    13.                 lstCopyFiles.Items.RemoveAt(0);
    14.             }
    15.         }
    Last edited by PsychoticPsymon; Apr 27th, 2006 at 06:31 AM.
    AZURE
    Act 1: Ruby
    Act 2: Cavara Militari
    Act 3:
    Act 4:
    Act 5: Cogito ergo sum

  4. #4
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: File.Copy() and other backuping information

    File.Copy(lstCopyFiles.SelectedItem.ToString(), lstDestination.SelectedItem.ToString(),true);

    On that line, is lstDestination.SelectedItem.ToString() giving you a full path or just the directory to put it in. It may be that you are only telling it the target directory, when you need to specify the whole thing..

    I.e, for parameter 1: "C:\BILL\JOE.TXT"

    for parameter 2: "C:\JOE\JOE.TXT" is ok but "C:\JOE\" is not ok..

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Location
    New York
    Posts
    94

    Re: File.Copy() and other backuping information

    !!!
    >.<

    If I may be so upfront, Conipto, I love you.
    AZURE
    Act 1: Ruby
    Act 2: Cavara Militari
    Act 3:
    Act 4:
    Act 5: Cogito ergo sum

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