Results 1 to 10 of 10

Thread: Edit my code plz

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    41

    Edit my code plz

    Code:
    System.IO.File.Move(@"ConsoleApplication2.exe", @"C:\windows\ConsoleApplication2.exe");
    Is there a way to make it only do this if there isn't a "ConsoleApplication2.exe" in
    "C:\windows\" ? Because right now, it keep doing it which makes it to shutdown. Thanks.

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Edit my code plz

    Code:
    if(System.IO.File.Exists(@"C:\windows\ConsoleApplication2.exe") == false)
    {
        System.IO.File.Move(@"ConsoleApplication2.exe", @"C:\windows\ConsoleApplication2.exe");
    }
    But I will say, write the whole path instead of just [ConsoleApplication2.exe].
    Show Appreciation. Rate Posts.

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    41

    Re: Edit my code plz

    Thanks, but wat u mean by:

    But I will say, write the whole path instead of just [ConsoleApplication2.exe].

  4. #4
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Edit my code plz

    Quote Originally Posted by Visionary
    Thanks, but wat u mean by:
    Nothing, sorry to bother you with my idiocy.
    Show Appreciation. Rate Posts.

  5. #5
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Edit my code plz

    Quote Originally Posted by Harsh Gupta
    Nothing, sorry to bother you with my idiocy.
    I don't know why the change of mind , you are right!!

    You must include the full path of ConsoleApplication2.exe So if the user moved the file (the current file) and tried to run it, it won't throw an exception in his face
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  6. #6
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Edit my code plz

    Quote Originally Posted by ComputerJy
    I don't know why the change of mind , you are right!!

    You must include the full path of ConsoleApplication2.exe So if the user moved the file (the current file) and tried to run it, it won't throw an exception in his face
    You are right, writing full path is a good practice, but if the exe (or any file) is located where your application is, then full path is not required.
    Show Appreciation. Rate Posts.

  7. #7
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Edit my code plz

    In that case it would be,
    Code:
    Application.StartupPath + "\\ConsoleApplication2.exe";
    But you also won't need doing this
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  8. #8

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    41

    Re: Edit my code plz

    I got it to work with Harsh's post. Thanks! No more questions on this.

  9. #9
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Edit my code plz

    Quote Originally Posted by Visionary
    I got it to work with Harsh's post. Thanks! No more questions on this.
    You can mark the Thread resolved from the "Thread Tools" menu
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Edit my code plz

    Quote Originally Posted by ComputerJy
    You can mark the Thread resolved from the "Thread Tools" menu
    Please do.

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