Click here to Skip to main content
15,884,904 members
Articles / Desktop Programming / MFC

Editing Unix Files in Windows

Rate me:
Please Sign up or sign in to vote.
1.39/5 (8 votes)
26 Jul 2006CPOL 34.9K   199   10   4
This is a very simple tool to edit Unix files in Windows.

Sample screenshot

Introduction

This tools allows you to edit files in Unix. vi is a good choice, but for Windows users, it is really a tough one. To simplify text editing, I have created a tool which actually downloads the file from a Unix server using FTP, and after editing it, uploads it back to the server.

Here are the files you need:

  • NetDirectoryDlg.cpp
  • FileEditor.cpp

It has only two dialogs:

  1. The NeDirectory dialog which captures the user ID, password, and server, and connects to the server and retrieves the file and directory information.
  2. Editor dialog which simply displays the file data.

This tool simply downloads the file from the server using FTP to a local machine. The local file is fed to the file editor. Once editing is done, it is uploaded back to the server using FTP.

I have used MFC's CFtpConnection for this.

The code

Connecting to the FTP server

C++
try
{
      if(inetsess==NULL)
      {
           inetsess=new CInternetSession();
      }
      else
      {
           inetsess->Close();
           inetsess=new CInternetSession();
      }
    ftp = inetsess->GetFtpConnection(m_server,m_user,m_pass);
}
catch(...)
{}
..
..
    GetFiles();
 }
}

Storing the records in the listbox

C++
CFtpFileFind ftpFind(ftp);
BOOL bcontinue=TRUE;
CString str;
/*search for records and update in list box*/
m_LstDir.ResetContent();
ftpFind.FindFile("");
while(bcontinue )
{
    bcontinue = ftpFind.FindNextFile();
      str = ftpFind.GetFileName();
      if(str.GetLength()>0)
      {
           if(ftpFind.IsDirectory())
           {
                str.Insert(0,"./");
           }
           m_LstDir.AddString(str);
      }
     }
     ftpFind.Close();
}

Double clicking the listbox and loading the file

C++
CString str;
CString strCurDir;
CFile file;
m_LstDir.GetText(m_LstDir.GetCurSel(),str);
if(str.Left(2)!="./")
{
    ftp->GetFile(str,str); /*get the file to local directory*/
    if(file.Open(str,CFile::modeRead))
    {
       file.Close();
       CFileEditor edit(str);
       if(edit.DoModal()==IDOK)
       {
            if(ftp->PutFile(str,str))
            {
                 AfxMessageBox("Server File Updated...",MB_OK);
            }
       }
       /*remove it in either case*/
       CFile::Remove(str);
    }
}
else
{
    if(ftp->GetCurrentDirectory(strCurDir))
    {
         strArrPath.Add(strCurDir);
    }
    if(ftp->SetCurrentDirectory(str))
    {
         GetFiles();
    }
}

It can be customized with features like a treeview control or a full Explorer like view.

License

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


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionI could not get it working Pin
Member 810166421-Jul-11 1:20
Member 810166421-Jul-11 1:20 
How do you run this? do you have some steps?
GeneralPlease fix your source download link! Pin
cristitomi18-Mar-07 8:48
cristitomi18-Mar-07 8:48 
GeneralHtmlKit Pin
Vasudevan Deepak Kumar21-Jul-06 2:34
Vasudevan Deepak Kumar21-Jul-06 2:34 
GeneralRe: HtmlKit Pin
B.Rajarajan23-Jul-06 18:34
B.Rajarajan23-Jul-06 18:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.