uberTraceur

Okay, I have done my fair share of fooling around in visual basic, but, C# is completely new to me.

I'm trying to make a program which will transfer files from a thumb drive (which you select), to a folder on the computer (which is selected also.) Or, there are presets (as this program is for a friend of mine), which will select things from preset drive names and preset folders. Then, you hit transfer, and it's supposed to copy from the thumb drive to a folder on your computer.

I basically want the program to, based on what you select, find the folder you want, with the extension you want, and copy and overwrite the updated files to a different folder.

I have the design stuff done, but the coding is bugging me. I have a text box, with a button next to it that allows you to choose a folder. (Which I want to display in the text box) and then another text box and folder chooser button below it. (Transfer from/Transfer to)

Then, beneath those, there is a group of radio buttons that define the presets, which would just be shortcuts to what you would have to do above. (Which I also want to display the folders in a text box)

Then, there's a 'are you sure you want to do this' checkbox, and I want to make that so, when checked, will make the transfer button un-greyed. Otherwise, the transfer button is greyed out.

The main function would be to copy files from a folder to another folder.

I set up a batch file to do this, that runs:

f:
cd \filefolder
copy *.doc c:\files


but, I want to put that into a nice application.

Any help on how to get started, code references, anything


Re: Visual C# General A Whole Load of Questions...

OmegaMan

uberTraceur wrote:


I set up a batch file to do this, that runs:

f:
cd \filefolder
copy *.doc c:\files


but, I want to put that into a nice application.

Any help on how to get started, code references, anything


You have two options:
  1. Use the Process Class to execute your batch file.
  2. Programmatically copy the files using the File.Copy Method to copy the files.







Re: Visual C# General A Whole Load of Questions...

uberTraceur

Ok, thanks. But, how can I set the "copy from" and "copy to" based on file inputs OR a selection from a group of radio buttons Also, I only want to copy files of a certain extension. How can I do that

Thanks again!





Re: Visual C# General A Whole Load of Questions...

Brad Wery

I'm just learning C# so please pardon me if I give the wrong suggestion

Couldn't you use the File and Directory classes found in the System.IO namespace to do what you want. The Directory class has a GetFiles method. You could loop through the results calling the Copy method in the File class.

Maybe something like this

string[] files = System.IO.Directory.GetFiles(@"C:\", "*.doc");

foreach (string file in files)

{

System.IO.File.Copy(file, @"c:\dest\" + file.Substring(file.LastIndexOf("\\"), file.Length - file.LastIndexOf("\\")), true);

}





Re: Visual C# General A Whole Load of Questions...

ThE_lOtUs

Brad, you could just do: @"c:\dest\" + System.IO.Path.GetFileName(file) to get the destination filename Smile





Re: Visual C# General A Whole Load of Questions...

Brad Wery

Nice! There's a lot to learn.





Re: Visual C# General A Whole Load of Questions...

uberTraceur

Yeah, I gt the how to copy the files part, but I want to know how I can get it so that the paths are either based on the user input, OR on which radio button is selected.




Re: Visual C# General A Whole Load of Questions...

Brad Wery

I guess I would have to see the app in order to fully understand what you're trying to do. You said the origin and destination paths were put into a text box so to get that wouldn't you just do this:

string[] files = System.IO.Directory.GetFiles(this.txtFromDir.Text, "*." + this.txtExtension.Text);

foreach (string file in files)

{

System.IO.File.Copy(file, this.txtToDir + System.IO.Path.GetFileName(file), true);

}





Re: Visual C# General A Whole Load of Questions...

OmegaMan

uberTraceur wrote:
Yeah, I gt the how to copy the files part, but I want to know how I can get it so that the paths are either based on the user input, OR on which radio button is selected.

Your question is now all over the board. The issue with winforms is a learning issue for you. I recommend that you begin work on reviewing example programs to get you up to speed. ....


Check out the 101 Samples for Visual Studio 2005 which is a robust, initial development tasks to more involved tasks for winforms, web development etc which may help you in other areas.

Check out the Windows Forms .Net (FAQ) which has differing lists of items, very helpful. Another FAQ which rounds up many subjects is the MSDN Winforms FAQ. Also check out is the GotDotNet Winforms Quick Start.