- Dec
- 4
- 0
Hi all,
So, I'm writing a batch file where I'm matching file names between two folders, but I'm only matching on part of the name - essentially an ID number. I'm trying to rename one set of files to match a different set of files, allowing for differing extensions. (I'm talking image files here, and some have been converted from JPG or PNG to WEBP.)
Here's what I've got:
As you can see, I'm making use of a Regular Expression to do the matching. The DIR command works exactly as I expect, finding matches correctly. But where it finds a single match (essentially a sanity check, because there should only ever be a single match, but you never know), when I use the @FINDFIRST function to then get the actual matched file it just comes back blank.
I've worked out that the problem is with including the path. If I change the working directory to \\NAS01\Images\%Artist% and do a test with:
%@FINDFIRST["::.*%ID%.(jpg|gif|png|webp|psd)$"]
(i.e. with all the path bit removed) then a match is found. But the documentation suggests that including a path in the @FINDFIRST function is fine, even including the example:
%@findfirst[/[s2k,3k] "%windir\*.exe",a]
So, what am I doing wrong?
NB: I'm still on version 28.00.10 of TCC at the moment.
Thanks,
Michael
So, I'm writing a batch file where I'm matching file names between two folders, but I'm only matching on part of the name - essentially an ID number. I'm trying to rename one set of files to match a different set of files, allowing for differing extensions. (I'm talking image files here, and some have been converted from JPG or PNG to WEBP.)
Here's what I've got:
@echo off
set Artist=%@NAME[%_CWD]
echo Scanning Artist %Artist%:
for %v in (.jpg;.gif;*.png) do (
echo Checking file: %v
set ID=%@INSTR[9,-11,%@NAME[%v]]
echo ID Determined as %ID%. Looking for match in \\NAS01\Images\%Artist%
DIR /B /Ne "::\\\\NAS01\\Images\\%Artist%\\.%ID%.(jpg|gif|png|webp|psd)$" > nul
IF %_dir_files EQ 1 (
set MatchedFile=%@FINDFIRST["::\\\\NAS01\\Images\\%Artist%\\.*%ID%.(jpg|gif|png|webp|psd)$"]
echo Found match! %MatchedFile%
ren "%v" "%@NAME[%MatchedFile%].%@EXT[%v]"
)
)
set MatchedFile=
set Artist=
set ID=
As you can see, I'm making use of a Regular Expression to do the matching. The DIR command works exactly as I expect, finding matches correctly. But where it finds a single match (essentially a sanity check, because there should only ever be a single match, but you never know), when I use the @FINDFIRST function to then get the actual matched file it just comes back blank.
I've worked out that the problem is with including the path. If I change the working directory to \\NAS01\Images\%Artist% and do a test with:
%@FINDFIRST["::.*%ID%.(jpg|gif|png|webp|psd)$"]
(i.e. with all the path bit removed) then a match is found. But the documentation suggests that including a path in the @FINDFIRST function is fine, even including the example:
%@findfirst[/[s2k,3k] "%windir\*.exe",a]
So, what am I doing wrong?
NB: I'm still on version 28.00.10 of TCC at the moment.
Thanks,
Michael