Connecting Tech Pros Worldwide Forums | Help | Site Map

split firstname and xtension of a file

Newbie
 
Join Date: Oct 2008
Location: kolkata
Posts: 30
#1: Oct 4 '08
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.

insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,608
#2: Oct 4 '08

re: split firstname and xtension of a file


System.IO.FileInfo can do everything you need.

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

If you need information on those members, there is a link at the bottom of the MSDN page I linked you to.
Newbie
 
Join Date: Oct 2008
Location: kolkata
Posts: 30
#3: Oct 21 '08

re: split firstname and xtension of a file


i have done this,

string sFile;
string fDoctype;
string opt;
sFile = "D:\\processedpcl\\ARG.OUT.WIRE.INFO0.doc";
string pfile = "D:\\processedfile" + "\\" + sFile;
fDoctype = pfile.Substring(pfile.LastIndexOf("\\") + 1);
Console.WriteLine(fDoctype);
opt = fDoctype.Substring(0, 3);
Console.WriteLine(opt);
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#4: Oct 21 '08

re: split firstname and xtension of a file


Quote:

Originally Posted by sweetneel

i have done this,

string sFile;
string fDoctype;
string opt;
sFile = "D:\\processedpcl\\ARG.OUT.WIRE.INFO0.doc";
string pfile = "D:\\processedfile" + "\\" + sFile;
fDoctype = pfile.Substring(pfile.LastIndexOf("\\") + 1);
Console.WriteLine(fDoctype);
opt = fDoctype.Substring(0, 3);
Console.WriteLine(opt);

There is really no need for all that reed dancing with that substring. Read insert's post above again.
Reply