Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12286

Re: Arrange files according to a text file

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.018
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'filename': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'skip:[ 30': 0.09; 'subject:files': 0.09; 'subject:file': 0.13; 'def': 0.15; 'comma': 0.16; 'filenames': 0.16; 'received:173.11': 0.16; 'sally': 0.16; 'header:In-Reply-To:1': 0.22; 'random': 0.28; 'separate': 0.28; 'import': 0.28; 'print': 0.29; 'list': 0.32; 'to:addr:python-list': 0.33; 'named': 0.33; 'header:User-Agent:1': 0.34; 'directory.': 0.34; 'like:': 0.34; 'header:X-Complaints- To:1': 0.35; 'subject:text': 0.35; 'file': 0.36; 'pull': 0.37; 'listed': 0.37; 'but': 0.37; 'something': 0.37; 'could': 0.38; 'received:org': 0.38; 'hello,': 0.38; 'some': 0.38; 'move': 0.38; 'subject:: ': 0.39; 'persons': 0.39; 'header:Mime-Version:1': 0.39; 'format.': 0.39; 'data': 0.39; 'to:addr:python.org': 0.39; "i'd": 0.40; 'more': 0.60; 'john': 0.62; 'business': 0.70; 'username': 0.77; '10:03': 0.84; 'directories,': 0.84; 'stone,': 0.84; 'stone': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Emile van Sebille <emile@fenx.com>
Subject Re: Arrange files according to a text file
Date Sat, 27 Aug 2011 11:06:22 -0700
References <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 173-11-108-137-sfba.hfc.comcastbusiness.net
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:6.0) Gecko/20110812 Thunderbird/6.0
In-Reply-To <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.473.1314468400.27778.python-list@python.org> (permalink)
Lines 63
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1314468400 news.xs4all.nl 2412 [2001:888:2000:d::a6]:38425
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:12286

Show key headers only | View raw


On 8/27/2011 10:03 AM Ric@rdo.python.org said...
> Hello,
>
> What would be the best way to accomplish this task?

I'd do something like:


usernames = """Adler, Jack
Smith, John
Smith, Sally
Stone, Mark""".split('\n')

filenames = """Smith, John - 02-15-75 - business files.doc
Random Data - Adler Jack - expenses.xls
More Data Mark Stone files list.doc""".split('\n')

from difflib import SequenceMatcher as SM


def ignore(x):
     return x in ' ,.'


for filename in filenames:
     ratios = [SM(ignore,filename,username).ratio() for username in 
usernames]
     best = max(ratios)
     owner = usernames[ratios.index(best)]
     print filename,":",owner


Emile



> I have many files in separate directories, each file name
> contain a persons name but never in the same spot.
> I need to find that name which is listed in a large
> text file in the following format. Last name, comma
> and First name. The last name could be duplicate.
>
> Adler, Jack
> Smith, John
> Smith, Sally
> Stone, Mark
> etc.
>
>
> The file names don't necessary follow any standard
> format.
>
> Smith, John - 02-15-75 - business files.doc
> Random Data - Adler Jack - expenses.xls
> More Data Mark Stone files list.doc
> etc
>
> I need some way to pull the name from the file name, find it in the
> text list and then create a directory based on the name on the list
> "Smith, John" and move all files named with the clients name into that
> directory.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Arrange files according to a text file Ric@rdo - 2011-08-27 13:03 -0400
  Re: Arrange files according to a text file MRAB <python@mrabarnett.plus.com> - 2011-08-27 18:22 +0100
  Re: Arrange files according to a text file Emile van Sebille <emile@fenx.com> - 2011-08-27 11:06 -0700
    Re: Arrange files according to a text file Ric@rdo - 2011-08-27 16:15 -0400
      Re: Arrange files according to a text file Emile van Sebille <emile@fenx.com> - 2011-08-27 14:08 -0700
        Re: Arrange files according to a text file Ric@rdo - 2011-08-27 19:18 -0400
          Re: Arrange files according to a text file MRAB <python@mrabarnett.plus.com> - 2011-08-28 00:48 +0100
            Re: Arrange files according to a text file Ric@rdo - 2011-08-27 20:21 -0400
          Re: Arrange files according to a text file Emile van Sebille <emile@fenx.com> - 2011-08-27 18:10 -0700
            Re: Arrange files according to a text file Ric@rdo - 2011-08-28 01:24 -0400
  Re: Arrange files according to a text file Stephen Hansen <me+list/python@ixokai.io> - 2011-08-27 16:31 -0700

csiph-web