split firstname and xtension of a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sweetneel
    New Member
    • Oct 2008
    • 42

    split firstname and xtension of a file

    i have a file named abc.pcl

    i want to convert it abc.dat

    in c#.net how to do it. i am fetching this file from a directory, and i have to save it as abc.dat.

    file name should be same, but extension is changed.

    thanx.
    neel.
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    System.IO.FileI nfo can do everything you need.

    The properties you will need are FullName, Name, and Extension. The method you can use is CopyTo(newPathS tring).

    If you need information on those members, there is a link at the bottom of the MSDN page I linked you to.

    Comment

    • sweetneel
      New Member
      • Oct 2008
      • 42

      #3
      i have done this,

      string sFile;
      string fDoctype;
      string opt;
      sFile = "D:\\processedp cl\\ARG.OUT.WIR E.INFO0.doc";
      string pfile = "D:\\processedf ile" + "\\" + sFile;
      fDoctype = pfile.Substring (pfile.LastInde xOf("\\") + 1);
      Console.WriteLi ne(fDoctype);
      opt = fDoctype.Substr ing(0, 3);
      Console.WriteLi ne(opt);

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by sweetneel
        i have done this,

        string sFile;
        string fDoctype;
        string opt;
        sFile = "D:\\processedp cl\\ARG.OUT.WIR E.INFO0.doc";
        string pfile = "D:\\processedf ile" + "\\" + sFile;
        fDoctype = pfile.Substring (pfile.LastInde xOf("\\") + 1);
        Console.WriteLi ne(fDoctype);
        opt = fDoctype.Substr ing(0, 3);
        Console.WriteLi ne(opt);
        There is really no need for all that reed dancing with that substring. Read insert's post above again.

        Comment

        Working...