Copy incrementing already existing suffix
-
- Posts: 5
- Joined: 03 May 2023 05:47
Copy incrementing already existing suffix
Hello!
I'm working on a project scanning thousands of documents as pdfs.
They are automatically named like CompanyName--EmployeeName--001.pdf, and the counter increases automatically (ex:--002.pdf) if I have more than one pdf with the same name on the same batch.
However, often I have the same company/employee on different batches, so i need to copy the CompanyName--EmployeeName--001.pdf (and hundreds of other files in subfolders) to a folder that has a file with the same name.
I tried to configure the suffix counter on XYplorer to match the one I used, but I end up with something like CompanyName--EmployeeName--001--001.pdf, CompanyName--EmployeeName--001--002.pdf.
Is there a way to fix this?
I'm working on a project scanning thousands of documents as pdfs.
They are automatically named like CompanyName--EmployeeName--001.pdf, and the counter increases automatically (ex:--002.pdf) if I have more than one pdf with the same name on the same batch.
However, often I have the same company/employee on different batches, so i need to copy the CompanyName--EmployeeName--001.pdf (and hundreds of other files in subfolders) to a folder that has a file with the same name.
I tried to configure the suffix counter on XYplorer to match the one I used, but I end up with something like CompanyName--EmployeeName--001--001.pdf, CompanyName--EmployeeName--001--002.pdf.
Is there a way to fix this?
Re: Copy incrementing already existing suffix
A real world scenario looks like?
Files in _test_suffix_src (including subfolders)
Let's say _test_suffix_dst contains:
So you now copy all 4 files from src to dst
you'd want a result like this?
?
Files in _test_suffix_src (including subfolders)
Code: Select all
D:\_test_suffix_src\CompanyName--EmployeeName--001.pdf
D:\_test_suffix_src\CompanyName--EmployeeName--002.pdf
D:\_test_suffix_src\sub\CompanyName--EmployeeName--001.pdf
D:\_test_suffix_src\sub\CompanyName--EmployeeName--002.pdf
Code: Select all
D:\_test_suffix_dst\CompanyName--EmployeeName--001.pdf
D:\_test_suffix_dst\CompanyName--EmployeeName--002.pdf
you'd want a result like this?
Code: Select all
D:\_test_suffix_dst\CompanyName--EmployeeName--001.pdf (stayed the same)
D:\_test_suffix_dst\CompanyName--EmployeeName--002.pdf (stayed the same)
D:\_test_suffix_dst\CompanyName--EmployeeName--003.pdf (original file: D:\_test_suffix_src\CompanyName--EmployeeName--001.pdf)
D:\_test_suffix_dst\CompanyName--EmployeeName--004.pdf (original file: D:\_test_suffix_src\CompanyName--EmployeeName--002.pdf)
D:\_test_suffix_dst\CompanyName--EmployeeName--005.pdf (original file: D:\_test_suffix_src\sub\CompanyName--EmployeeName--001.pdf)
D:\_test_suffix_dst\CompanyName--EmployeeName--006.pdf (original file: D:\_test_suffix_src\sub\CompanyName--EmployeeName--002.pdf)
One of my scripts helped you out? Please donate via Paypal
-
- Site Admin
- Posts: 60598
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Copy incrementing already existing suffix
Disappearing as a way of saying thank you.
FAQ | XY News RSS | XY Twitter
-
- Posts: 5
- Joined: 03 May 2023 05:47
Re: Copy incrementing already existing suffix
Heyy, sorry for the late response! I have been really busy these days.
Some personal and professional issues happening rn.
I was evicted from where I lived, so had to move to my home town.
Anyway, I really appreciate the help!
-
- Posts: 5
- Joined: 03 May 2023 05:47
Re: Copy incrementing already existing suffix
Heyy! Sorry for the delayed response.highend wrote: ↑03 May 2023 09:20 A real world scenario looks like?
Files in _test_suffix_src (including subfolders)Let's say _test_suffix_dst contains:Code: Select all
D:\_test_suffix_src\CompanyName--EmployeeName--001.pdf D:\_test_suffix_src\CompanyName--EmployeeName--002.pdf D:\_test_suffix_src\sub\CompanyName--EmployeeName--001.pdf D:\_test_suffix_src\sub\CompanyName--EmployeeName--002.pdf
So you now copy all 4 files from src to dstCode: Select all
D:\_test_suffix_dst\CompanyName--EmployeeName--001.pdf D:\_test_suffix_dst\CompanyName--EmployeeName--002.pdf
you'd want a result like this??Code: Select all
D:\_test_suffix_dst\CompanyName--EmployeeName--001.pdf (stayed the same) D:\_test_suffix_dst\CompanyName--EmployeeName--002.pdf (stayed the same) D:\_test_suffix_dst\CompanyName--EmployeeName--003.pdf (original file: D:\_test_suffix_src\CompanyName--EmployeeName--001.pdf) D:\_test_suffix_dst\CompanyName--EmployeeName--004.pdf (original file: D:\_test_suffix_src\CompanyName--EmployeeName--002.pdf) D:\_test_suffix_dst\CompanyName--EmployeeName--005.pdf (original file: D:\_test_suffix_src\sub\CompanyName--EmployeeName--001.pdf) D:\_test_suffix_dst\CompanyName--EmployeeName--006.pdf (original file: D:\_test_suffix_src\sub\CompanyName--EmployeeName--002.pdf)
It`s somewhat like this, but not exactly. But the final effect I think would be the same.
_test_suffix_src:
Code: Select all
D:\_test_suffix_src\CompanyName\EmployeeName\CompanyName--EmployeeName--001.pdf
D:\_test_suffix_src\CompanyName\EmployeeName\CompanyName--EmployeeName--002.pdf
_test_suffix_dst contains:
Code: Select all
D:\_test_suffix_dst\CompanyName\EmployeeName\CompanyName--EmployeeName--001.pdf
D:\_test_suffix_dst\CompanyName\EmployeeName\CompanyName--EmployeeName--002.pdf
Code: Select all
D:\_test_suffix_dst\CompanyName\EmployeeName\CompanyName--EmployeeName--001.pdf
D:\_test_suffix_dst\CompanyName\EmployeeName\CompanyName--EmployeeName--002.pdf
D:\_test_suffix_dst\CompanyName\EmployeeName\CompanyName--EmployeeName--003.pdf
D:\_test_suffix_dst\CompanyName\EmployeeName\CompanyName--EmployeeName--004.pdf
I usually copy one or two companies at the same time, hundreds of employees subfolders and files inside. I just need to merge the src with the dst, incrementing the suffix counter.
-
- Site Admin
- Posts: 60598
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Copy incrementing already existing suffix
Okay, sorry for my somewhat hasty comment from the sidelines. And sorry for your fate.thalesv666 wrote: ↑29 May 2023 23:17Heyy, sorry for the late response! I have been really busy these days.
Some personal and professional issues happening rn.
I was evicted from where I lived, so had to move to my home town.
Anyway, I really appreciate the help!
It's not my thread so I'll be quiet now.
FAQ | XY News RSS | XY Twitter
Re: Copy incrementing already existing suffix
- Open both panes
- In the right / lower you'll open your destination folder
- In the left you'll navigate to the root source folder
- If you have files in subdirectories there, use a branch view
Select all files that need to be copied
If your branch view shows folders it doesn't matter if you select them as well, the script ignores them
- Execute the script, do this with test data before (make a backup copy of your destination folder) you use it in production
If your destination folder contains gaps in your suffixes, the script won't fill them, it uses the highest one and proceeds with that!
dst folder:
and you copy
you'll end with:
- In the right / lower you'll open your destination folder
- In the left you'll navigate to the root source folder
- If you have files in subdirectories there, use a branch view
Select all files that need to be copied
If your branch view shows folders it doesn't matter if you select them as well, the script ignores them
- Execute the script, do this with test data before (make a backup copy of your destination folder) you use it in production
If your destination folder contains gaps in your suffixes, the script won't fill them, it uses the highest one and proceeds with that!
dst folder:
Code: Select all
D:\_test_suffix_dst\CompanyName--EmployeeName--002.pdf
D:\_test_suffix_dst\CompanyName--EmployeeName--005.pdf
Code: Select all
D:\_test_suffix_src\CompanyName--EmployeeName--001.pdf
D:\_test_suffix_src\CompanyName--EmployeeName--002.pdf
Code: Select all
D:\_test_suffix_dst\CompanyName--EmployeeName--001.pdf (the copied --001.pdf)
D:\_test_suffix_dst\CompanyName--EmployeeName--002.pdf (already existed in dst)
D:\_test_suffix_dst\CompanyName--EmployeeName--005.pdf (already existed in dst)
D:\_test_suffix_dst\CompanyName--EmployeeName--006.pdf (the copied --005.pdf)
Code: Select all
// Copy files (requires dual pane mode!) and increment their suffix
end (!get("#800")), "No dual pane active, aborted!";
$aItems = <get SelectedItemsPathNamesSlashed>;
$aFiles = formatlist($aItems, "f", <crlf>, "!*\");
end (!$aFiles), "No file(s) selected in active pane, aborted!";
// Files in inactive pane
$iPath = get("path", "i");
$iFiles = listfolder($iPath, , 1+4, <crlf>);
$toCopy = "";
foreach($aFile, $aFiles, <crlf>, "e") {
$file = gpc($aFile, "file");
$base = gpc($aFile, "base");
$ext = gpc($aFile, "ext");
$escFile = regexreplace($file, "([\\^$.+()\[{])", "\$1");
// File doesn't exist yet
if (!regexmatches($iFiles, $escFile)) {
$iFiles .= <crlf> . $file;
copyitem $aFile, $iPath . "\" . $file;
// File does exist
} else {
// Get source file suffix and the highest suffix of existing files
$aSuffix = regexmatches($base, "\d+?$");
$iSuffix = gettoken(regexmatches(regexreplace($iFiles, "\.[^.]+?$"), "\d+?$", <crlf>), -1, <crlf>);
// Create new file name and copy...
$lenISuffix = strlen($iSuffix);
$newSuffix = format($iSuffix + 1, strrepeat("0", $lenISuffix));
$newFile = regexreplace($base, "\d+?$", $newSuffix) . "." . $ext;
$iFiles .= <crlf> . $newFile;
copyitem $aFile, $iPath . "\" . $newFile;
}
}
One of my scripts helped you out? Please donate via Paypal
-
- Posts: 5
- Joined: 03 May 2023 05:47
Re: Copy incrementing already existing suffix
Thank you very much! I`m going to try that script today!
Last edited by thalesv666 on 20 Jun 2023 17:48, edited 1 time in total.
Re: Copy incrementing already existing suffix
...and for the "Thank you" at the bottom we needed a full quote of the post just above.
Ralph
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)
-
- Posts: 5
- Joined: 03 May 2023 05:47
Re: Copy incrementing already existing suffix
Sorry for the late response again, this case only happens sometimes at work, so I had to wait until I had a subject to test.
Looks like the script didn't work. Tested it with yesterday's work, a company with 300 or so employees. I had 7 files named COMPANY NAME--OUTROS---001.pdf to 007.pdf on the destination folder (OUTROS is the result I get when the employee name isn't found by my python script) and 103 files with the same name on the current working folder. I didn't even used the subfolders yet, but after running the script, the destination had 103 files with that name, kept the 7 that were there already and I got 7 windows popups to skip those files or overwrite.
When I originally posted I was looking for a way to modify the original "rename suffix" to detect if the filename already has a suffix, or force it to substitute the last 3 digits in every filename. Is this possible?
Need work on my forum skills.
I don't usually post anywhere, my english isn't very good. I can often just read and find what I need, but in this case looks like no one have this kind of problem.
Last time I posted somewhere must've been years ago.
Looks like the script didn't work. Tested it with yesterday's work, a company with 300 or so employees. I had 7 files named COMPANY NAME--OUTROS---001.pdf to 007.pdf on the destination folder (OUTROS is the result I get when the employee name isn't found by my python script) and 103 files with the same name on the current working folder. I didn't even used the subfolders yet, but after running the script, the destination had 103 files with that name, kept the 7 that were there already and I got 7 windows popups to skip those files or overwrite.
When I originally posted I was looking for a way to modify the original "rename suffix" to detect if the filename already has a suffix, or force it to substitute the last 3 digits in every filename. Is this possible?
Yeah, and I double posted just before that too.
Need work on my forum skills.
I don't usually post anywhere, my english isn't very good. I can often just read and find what I need, but in this case looks like no one have this kind of problem.
Last time I posted somewhere must've been years ago.
Re: Copy incrementing already existing suffix
No, not with any inbuilt optionWhen I originally posted I was looking for a way to modify the original "rename suffix" to detect if the filename already has a suffix, or force it to substitute the last 3 digits in every filename. Is this possible?
I've tested the script with:
First pane path:
D:\_test_suffix_src
103 files:
Code: Select all
COMPANY NAME--OUTROS---001.pdf
...
COMPANY NAME--OUTROS---103.pdf
Second pane path:
D:\_test_suffix_dst
7 files
Code: Select all
COMPANY NAME--OUTROS---001.pdf
...
COMPANY NAME--OUTROS---007.pdf
D:\_test_suffix_dst
contains 110 files
Code: Select all
COMPANY NAME--OUTROS---001.pdf
...
COMPANY NAME--OUTROS---110.pdf
One of my scripts helped you out? Please donate via Paypal