Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Moving A File [Snippet]

Moving it in C#


Hey, Just thought I would show you all how to move a file in C#. As I'm sure you can imagine, this can be used for many different things. You could use it for malware, or even legitimate reasons.

I'm sure someone here can come up with something!

[IMG]http://img545.imageshack.us/img545/272/37084486.gif[/IMG]

Usings
Code
using System.IO;

Variables
Please Submit File Locations For Your Own!
Code
string currentloc = "C:\\Users\\Smith\\Desktop\\test doc.txt";
    string folderloc = "C:\\Users\\Smith\\Desktop\\New folder";
    string newloc = "C:\\Users\\Smith\\Desktop\\New folder\\test doc.txt";

Moving It
Code
try
    {
    if (Directory.Exists(folderloc))
    {

    if (File.Exists(currentloc))
    {
    File.Move(currentloc, newloc);

    }

    else
    {
    MessageBox.Show("Invalid File");
    }
    }
    else
    {
    MessageBox.Show("Invalid Directory");
    }
    }

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

Usage:
Code
File.Move(currentloc, newloc);
http://www.pulsecodes.info
Computer and Information Science major.
Information Technology Apprentice.
Freelance Programmer.
You could've post the MSDN page instead of typing this...

http://msdn.microsoft.com/en-us/library/c6cfw35a.aspx
(Nov 14, 2010 12:02 PM)H3x0S Wrote:  You could've post the MSDN page instead of typing this...

http://msdn.microsoft.com/en-us/library/c6cfw35a.aspx

Probably, a lot of what is posted on this forum can be found by a simple Google search. However, I would think me being here to help as well as posting a simplified way of doing it (compared to MSDN), would make it a bit easier on beginners.

Thanks for the comment. 👍
http://www.pulsecodes.info
Computer and Information Science major.
Information Technology Apprentice.
Freelance Programmer.
(Nov 14, 2010 12:02 PM)H3x0S Wrote:  You could've post the MSDN page instead of typing this...

http://msdn.microsoft.com/en-us/library/c6cfw35a.aspx

I doubt 90% of the people on this forum even know that MSDN even exists.
(Nov 14, 2010 12:15 PM)ident Wrote:  I doubt 90% of the people on this forum even know that MSDN even exists.

lol, thanks for the comment ident. Always glad to see people who think the same way as me.
http://www.pulsecodes.info
Computer and Information Science major.
Information Technology Apprentice.
Freelance Programmer.
thanks for posting! I love your tuts and examples, they are always simple.
This is not a tutorial. Nothing is explain here.
(Nov 14, 2010 12:28 PM)H3x0S Wrote:  This is not a tutoria. Nothing is explain here.

It is not a step by step tutorial, however, it does show you how to do something.

So, maybe consider it a "guide" on how to move a file.

Also, thanks for the positive comment Mr. Anderson.
http://www.pulsecodes.info
Computer and Information Science major.
Information Technology Apprentice.
Freelance Programmer.
No, it's not a guide, it's a snippet.
(Nov 14, 2010 12:41 PM)H3x0S Wrote:  No, it's not a guide, it's a snippet.

Okay, a snippet then.

Why does it matter?
http://www.pulsecodes.info
Computer and Information Science major.
Information Technology Apprentice.
Freelance Programmer.
(Nov 14, 2010 12:43 PM)Pulser Wrote:  Okay, a snippet then.

Why does it matter?

Well, if someone wants to see a tutorial for moving a file, he expects the real tutorial with explanations. 🙂
(Nov 14, 2010 12:46 PM)H3x0S Wrote:  Well, if someone wants to see a tutorial for moving a file, he expects the real tutorial with explanations. 🙂

Well, that makes sense. However, I never specified that it was a tutorial in the OP :D

I'm going to add in that it is just a snippet. Thanks for the comments :D
http://www.pulsecodes.info
Computer and Information Science major.
Information Technology Apprentice.
Freelance Programmer.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by еlixirSep 9, 2022 06:31 AM 0 132 Sep 9, 2022 06:31 AM
Last Post: еlixir
[Python] by datguy.devNov 28, 2019 10:37 PM 4 297 Nov 28, 2019 10:37 PM
Last Post: Eternal Darkness
[C#] by gigajewDec 1, 2018 05:55 PM 3 250 Dec 1, 2018 05:55 PM
Last Post: gigajew