Click here to Skip to main content
Click here to Skip to main content

Editing Unix Files in Windows

, 26 Jul 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
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

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

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

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)

Share

About the Author

B.Rajarajan
Web Developer
India India
No Biography provided

Comments and Discussions

 
QuestionI could not get it working PinmemberMember 810166421-Jul-11 2:20 
GeneralPlease fix your source download link! Pinmembercristitomi18-Mar-07 9:48 
GeneralHtmlKit PinmemberVasudevan Deepak Kumar21-Jul-06 3:34 
GeneralRe: HtmlKit PinmemberB.Rajarajan23-Jul-06 19:34 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141220.1 | Last Updated 27 Jul 2006
Article Copyright 2006 by B.Rajarajan
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid