Inexplicable error when renaming files using a CSV format ta

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Good morning Mr. Noodle,

I've written on this forum before, presenting some issues, and I've always received excellent support from you. You've consistently opened my eyes, pointing out the errors I've made while creating rules.

Right now, I'm facing a new problem. I've learned that before presenting my doubts, I need to conduct several investigations. I've done so, but I can't pinpoint the issue.

I'll try to explain it in words.

I work in Digital Printing and use Hazel for my workflows. Sometimes, I receive Excel lists with many models, and Hazel helps me organize and rename my files.

I've programmed several rules to filter, copy, and rename my files using CSV tables, and everything works perfectly fine. However, the last rule produces an error that has me puzzled.

I have a folder with various subfolders (one for each printing material), and each contains hundreds of PDF files with the following structure:

"Incremental number" "unique numerical code" "xN" where N is the number of copies to be printed for each PDF file.

Example:
1 1223004 x1
2 1225441 x1
3 1225488 x1
4 1225535 x1
5 1225633 x4
6 1225634 x3

Each file is delivered to a specific center, and those with multiple copies are distributed to various centers.

I have a CSV file where I've grouped each unique numerical code with the corresponding city for product delivery.

Example:
1223004, BURGOS x1
1225441, BURGOS x1
1225488, BURGOS x1
1225535, BURGOS x1
1225582, BURGOS x1
1225633, TUDE x1 - ZAMO x1 - XATI x1 - SAN ANTONIO x1
1225634, VIC x1 - VILAS x1 - TERRASSA x1

The last rule (the one causing errors I can't understand) consists of two rules.

The first one acts on the main folder with the condition:
If Kind is Folder
Resulting in:
Run Rules on folder content

The second rule has the condition:
If the file name matches (any text) (unique numerical code) (any text)
Resulting in:
Rename with pattern (name) (Second column of the CSV) extension

So, the files:
1 1223004 x1
2 1225441 x1
3 1225488 x1
4 1225535 x1
5 1225633 x4
6 1225634 x3

Are renamed as follows:
1 1223004 x1 BURGOS x1
2 1225441 x1 BURGOS x1
3 1225488 x1 BURGOS x1
4 1225535 x1 BURGOS x1
5 1225633 x4 TUDE x1 - ZAMO x1 - XATI x1 - SAN ANTONIO x1
6 1225634 x3 VIC x1 - VILAS x1 - TERRASSA x1

In general, the rule works perfectly, but in some cases, an error like this occurs:

The file that should be named:
50 1511379 x7 TORR x1 - HUELVA x1 - TUDE x1 - ZAMO x1 - XATI x1 - BURGOS x1 - SAN ANTONIO x1

Ends up being named:
50 1511379 x7 TORR x1 - HUELVA x1 - TUDE x1 - ZAMO x1 - XATI x1 - BURGOS x1 - SAN ANTONIO x1 TORR x1 - HUELVA x1 - TUDE x1 - ZAMO x1 - XATI x1 - BURGOS x1 - SAN ANTONIO x1

Meaning, the center names are duplicated.

The most surprising thing is that it always and only duplicates the center names in the same files. For example, if I have 300 files and apply the rule, the same files are always affected (e.g., number 50, number 62, and number 68).

I've tested applying the rule ONLY to those three files, and I get the correct name.

I'm not sure if my explanation is clear; I've written everything in Spanish and I'm translating it with ChatGPT, hoping it's understandable.

I'm quite confident in this case that I haven't made logical errors while preparing the rule. I have a feeling, which is probably wrong, that the sheer amount of data and the speed of the computer somehow lead to a glitch at specific points in the process (always in the same files), causing them to be renamed twice.

Thank you very much in advance for your response
Rivederlestelle
 
Posts: 11
Joined: Thu Jan 12, 2023 4:44 am

My guess is your renaming rule matches the renamed files and causes a loop. You should fix it so that after a file is renamed, it can't match that rule again. You can either tighten up the pattern or do something like add a tag.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thank you very much for your quick response. I don't quite understand how a loop can occur, but the solution works perfectly; adding a label immediately after renaming the file solves the problem. Thanks once again.

P.S. I am eager to learn about the new features in version 6 of your excellent program.
Rivederlestelle
 
Posts: 11
Joined: Thu Jan 12, 2023 4:44 am


Return to Support

cron