Re: What language to manipulate text files



ross wrote:
I want to do some tricky text file manipulation on many files, but have
only a little programming knowledge.

What are the ideal languages for the following examples?

1. Starting from a certain folder, look in the subfolders for all
filenames matching *FOOD*.txt Any files matching in each folder should
be copied to a new subfolder within the current folder called EATING
with a new name of *FOOD*COPY.txt

This should get you started:

import errno
from path import path # http://www.jorendorff.com/articles/python/path/

dst_dirpath = path("EATING")

# create dst_dirpath
try:
    dst_dirpath.makedirs() # make destination directory and its parents
except OSError, err:       # error!
    if err.errno = errno.EEXIST: # might just be that it already exists
        if not dst_dirpath.isdir(): # and it's a directory
            raise          # if not, raise an exception

for filepath in path(".").walkfiles("*FOOD*.txt"):
    infile = file(filepath)
    outfile = file(dst_dirpath.joinpath(filepath.namebase+"_COPY.txt"))

    ...do processing here...

My first objective is to process the files as described.
My second objective is to learn the best language for this sort of text
manipulation. The language should run on Windows 98, XP and Linux.

Would Python be best, or would a macro-scripting thing like AutoHotKey
work?

Personally, I'd use Python, but what do you expect when you ask here? -- Michael Hoffman .



Relevant Pages

  • Re: Add folder & sub folders to favorites
    ... Well, I have a folder, "Programming." ... it does have a number of subfolders, one for each language I work in. ...
    (microsoft.public.outlook.general)
  • Re: What language to manipulate text files
    ... Starting from a certain folder, look in the subfolders for all ... > filenames matching *FOOD*.txt Any files matching in each folder should ... Or "mmv", a linux utility: ...
    (comp.lang.python)
  • RE: Disappearing Network Share Subfolders
    ... Thank you for posting to the SBS Newsgroup. ... I understand that some of your Windows XP SP2 clients cannot view the ... subfolders in share folders on SBS 2K Server. ... Does the problematic share folder locate at NTFS or FAT32 disk? ...
    (microsoft.public.windows.server.sbs)
  • Re: Read path from text file to process directory structure
    ... Public Function fGetFolder(sFolderName As String) ... Dim FoldersArray As Variant ... 'Read all subfolders of the specified folder into an array ... 'The following string will contain the path of the folder which is currently ...
    (microsoft.public.word.vba.general)
  • Re: NTFS Permissions Question
    ... Answer is, modify includes delete, but not delete subfolders and files. ... subfolder(s) when delete is not inherited from the parent folder. ... with just the permission you need. ...
    (microsoft.public.cert.exam.mcse)