help with counter

Kevin@Cazabon.com kevin at cazabon.com
Tue Jan 7 01:51:51 CET 2003


IF your source files will always have a number in them like your example, it
should be easy.

1)  break the input filename into pieces so you can extract the number
(filename = string.split(filename, ".") would work for your example)

2)  get the number out of the resulting list:  (filenumber =
string.atoi(filename[1]) for your example)

3)  if the number is divisible by 3 evenly, don't write an output file (you
can add an offset if it's not the right file):  if (filenumber + offset) %3
== 0:  # skip this file

I hope that helps,

Kevin.


"Bill Carter" <BC at energy.com> wrote in message
news:83oj1v8eb814lev3bgtfqjpnpha92des1s at 4ax.com...
> I must have been looking at this problem for to  long, but I need some
> help because I am stuck.
>
> I have a series of files on disk   file.01.txt, file.02.txt ...
> what I am trying to do is rename all the files a new name but also not
> renaming a few files but maintaining the number sequence
>
> for example
>
> #sample command line
> pyrename.py file.01.txt file.400.txt  3 newfile.01.txt
>
> # breakdown
> script name / filename of first file / last filename / drop every 3rd
> file / new filename and start number
>
>
> should produce
>
> file.01.txt     newfile.01.txt
> file.02.txt newfile.02.txt
> file.03.txt
> file.04.txt newfile.03.txt
> file.05.txt newfile.04.txt
> file.06.txt newfile.05.txt
> file.07.txt newfile.06.txt
> file.08.txt
> file.09.txt newfile.07.txt
> file.10.txt ... newfile.08.txt...
>
> the filename changes the amount changes and the file to be dropped
> changes.
>
> For some reason I can't put my head around this problem.  Any help
> would be appreciated.
>
> BC
>
>






More information about the Python-list mailing list