Click here to Skip to main content
Licence CPOL
First Posted 21 Jul 2006
Views 18,544
Downloads 72
Bookmarked 10 times

Editing Unix Files in Windows

By | 26 Jul 2006 | Article
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)

About the Author

B.Rajarajan

Web Developer

India India

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionI could not get it working PinmemberMember 81016641:20 21 Jul '11  
GeneralPlease fix your source download link! Pinmembercristitomi8:48 18 Mar '07  
GeneralHtmlKit PinmemberVasudevan Deepak Kumar2:34 21 Jul '06  
GeneralRe: HtmlKit PinmemberB.Rajarajan18:34 23 Jul '06  

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.

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