Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Good evening,

How do I remove the ".pem" in the filename to change to ".ppk"

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SimplePEMCalculator
{
    class clsConvert
    {
        private string FilePath, OutputPath, WinSCPPath;
        public clsConvert(string fpath, string opath, string ppath)
        {
            FilePath = fpath;
            OutputPath = opath;
            WinSCPPath = ppath;
        }
     
        public int doConvert()
        {
            //try conversion 
            try
            {
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                startInfo.FileName = WinSCPPath + "\\" + "winscp.com";
                //forming the ouput file by getting the input filename and adding the current date
                string outputfile = FilePath.Substring(FilePath.LastIndexOf("\\") + 1) + ".ppk" ;
                string op = OutputPath + "\\"+outputfile;
                startInfo.Arguments = "/keygen " + FilePath + " -o " + op;
                process.StartInfo = startInfo;
                process.Start();
                process.Close();
                return 1; 
            }
            catch
            {
                return 0;
            }
        }
    }
}


What I have tried:

I have tried some options and came up empty and with errors.

Thanks again!
Posted
Updated 1-Jan-17 19:53pm
v2
Comments
[no name] 31-Dec-16 2:37am    
Richard MacCutchan 31-Dec-16 3:42am    
That should be a Solution.
Philippe Mori 31-Dec-16 13:21pm    
You should never do explicit string manipulation on filenames when there are already functions that does that in System.IO.Path class.

And learning how to use Google or some other search engine would be a good resolution for 2017. With very minimal search competence, one can find that in less than 10 seconds (Bing: c# remove file extention - first result) : Remove file extension from a file name string

1 solution

As Bruno (0x01AA[^]) and Philippe Mori[^] mentioned in the comments to the question, you have to use Path class[^], for example:
Path.GetFileName Method (String) (System.IO)[^]
Path.GetFileNameWithoutExtension Method (String) (System.IO)[^]
Path.GetExtension Method (String) (System.IO)[^]

Try! Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900