Results 1 to 2 of 2

Thread: Any filename instead of specified one

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    41

    Any filename instead of specified one

    Code:
    System.IO.File.Move(@"ConsoleApplication2.exe", @"C:\CA\ConsoleApplication2.exe");
    I am using this code and I was wondering if I can set the @"ConsoleApplication2.exe", where the "ConsoleApplication2.exe" part can be a variable. Which I mean instead of specifying the filename, there is a variable instead for the file's current name. I hope you guys will understand what I am asking.

    Example:

    %var = file's current name
    Say my file's name is TODD.exe so %var = Todd.exe
    Code:
    System.IO.File.Move(@"%var", @"C:\CA\%var");

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Any filename instead of specified one

    You're trying to make this more complex than it is. Move takes two string arguments. In the code you've posted you're passing literal strings but you can pass string variables too, just like you can pass variables to any method, as long as they're the correct type.
    Code:
    string var = "Todd.exe"; // This file name can come from anywhere, e.g. literal, TextBox, file, registry, etc.
    
    System.IO.File.Move(var, @"C:\CA\" + var);
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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