[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: not wanting to delete somebody's home directory

On 2019-07-05 at 11:45, Greg Wooledge wrote:

> On Fri, Jul 05, 2019 at 11:37:13AM -0400, The Wanderer wrote:
>> On 2019-07-05 at 11:32, mick crane wrote:
>>> after they get made I rename them all in consecutive order and if
>>>  there's other files in there the number order will get messed
>>> up.
>> Then the obvious solution would seem to be: before even starting,
>> check whether there are any files in the directory that don't match
>> the naming pattern you expect - or, even more importantly, any
>> subdirectories - and, if so, abort with an error message and don't
>> do anything.
> Or... keep track of the files you created, and only rename *those*
> files, not all the files that happen to be in the directory.

And what if some of the destination names already exist? That's the
point of deleting the existing files, I'd imagine. (Along with ensuring
that a subsequent program can safely assume that all files in the
resulting directory follow a defined naming pattern and have a defined
relationship to one another, which is one of the few use cases I can
think of for that type of automatic renaming.)

> Or... give your files the correct names in the first place, so you
> don't have to rename them in a second pass.

I'd guess that what names are correct may depend on information that
can't be known at the start of the process.

E.g., if you're wanting the files to be named in sequential numeric
order but zero-padded to the width of the highest-numbered file, you
can't know how many digits of padding you need to add to the first file
until you know how many files will have been created - and that might
not be practically determinable except by actually going through and
creating them.

That would also fit with a likelihood of filename collisions, and with
having it be problematic to just skip the existing filenames and leave
any existing files untouched.

   The Wanderer

The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all
progress depends on the unreasonable man.         -- George Bernard Shaw

Attachment: signature.asc
Description: OpenPGP digital signature

Reply to: