ExifTool Forum

ExifTool => Newbies => Topic started by: j99mac on October 28, 2021, 04:55:02 PM

Title: find and renaming
Post by: j99mac on October 28, 2021, 04:55:02 PM
is it posable to use a find and combidine it will renaming file?
Title: Re: find and renaming
Post by: StarGeek on October 28, 2021, 05:15:10 PM
I don't understand the question.
Title: Re: find and renaming
Post by: j99mac on October 28, 2021, 06:52:07 PM
I am looking to combine exiftool with find "filepath -iname "*_s*" ; && find "filepath -iname "*_f*" ; rename file that have _s one filenmae and file that have -f in them another filename.

The OS I am using is OSX 10.15 and the lastest version of exiftools I am also working with .tif files
Title: Re: find and renaming
Post by: StarGeek on October 28, 2021, 07:00:12 PM
I'd suggest redirecting the output from find into a temp file.  Hopefully, find is just giving the a list of the file paths.  You can then use the -@ (Argfile) option (https://exiftool.org/exiftool_pod.html#ARGFILE) to pass the list to exiftool.

Basically, something like this if you were removing the _s part
exiftool "-Filename<${Filename;s/_s//}" -@ OutputFromFind.txt
Title: Re: find and renaming
Post by: j99mac on October 29, 2021, 08:37:44 AM
I am waniting to do this if filename contains or is then change file name

would this work
exiftool -r -if '$Filename=~/_s\.tif/i' - FileName<${CreateDate;DateFmt("%Y%m%d")}_fadgi19264_$TargetNum_${CreateTime;DateFmt("%H%M")}_Start%.2nc.%e/"
Title: Re: find and renaming
Post by: StarGeek on October 29, 2021, 09:42:25 AM
You need quotes around the second half due to the < sign.  You only have a double quote at the very end and double quotes around the whole thing will make the terminal treat all dollar signs as shell variables instead of exiftool tags.  And I don't recall any tag called "TargetNum" so I don't know what you're doing there.

But otherwise, the syntax is correct.
Title: Re: find and renaming
Post by: j99mac on December 06, 2021, 01:04:56 PM
When running this how do I know it is going to run on a protocolar dir and file?

Quote from: j99mac on October 29, 2021, 08:37:44 AM
I am wanting to do this if filename contains or is then change file name

would this work
exiftool -r -if '$Filename=~/_s\.tif/i' - FileName<${CreateDate;DateFmt("%Y%m%d")}_fadgi19264_$TargetNum_${CreateTime;DateFmt("%H%M")}_Start%.2nc.%e/"
Title: Re: find and renaming
Post by: Phil Harvey on December 07, 2021, 08:15:13 AM
You must specify the directory on the command line.

- Phil
Title: Re: find and renaming
Post by: j99mac on December 07, 2021, 09:34:21 AM
When I run this command with a full link path at the end it works. But if the path is a variable then it does not work.
exiftool '-FileName<${CreateDate;DateFmt("%Y%m%d")}_target_'$tNum'_${DateTimeCreated;DateFmt("%H%M")}_finsh_'$type1'.%e $path

I would also like it to run base on the the filename is. Example if filename is abc_target_finsh then name the file with _finsh at the end

Do I need to put the the variable in quotes "$path" at the end of the script?
Also if there are multiple folders
example
abc/test
abc_test_finsh

abcd/test
abcd_test_finsh

How can how can I get the script to run recursively on files in subdir
Title: Re: find and renaming
Post by: j99mac on December 07, 2021, 01:35:26 PM
I am running the following command to rename files. When I run exiftool -r it only rename one of the sub directories. Is there another way to run exiftool to rename files recursively?

echo "Enter the file path"
read path
cd $path
find $path -iname "*target*" ;
   exiftool -r '-FileName<${CreateDate;DateFmt("%Y%m%d")}_test_${CreateDate;DateFmt("%H%M")}_start.%e' **/*_start.tif
   exiftool -r '-FileName<${CreateDate;DateFmt("%Y%m%d")}_test_${CreateDate;DateFmt("%H%M")}_finsh.%e' **/*_finsh.tif
exit 0
Title: Re: find and renaming
Post by: StarGeek on December 07, 2021, 02:03:27 PM
Quote from: j99mac on December 07, 2021, 01:35:26 PMIs there another way to run exiftool to rename files recursively?

You can't use wildcards and recurse.  See the -r (-recurse) option (https://exiftool.org/exiftool_pod.html#r-.--recurse) and Common Mistake #2c (https://exiftool.org/mistakes.html#M2).

You'll have to filter using the -if option (https://exiftool.org/exiftool_pod.html#if-NUM-EXPR) and RegEx.  For example
-if '$Filename=~/_finsh.tif/'
Title: Re: find and renaming
Post by: j99mac on December 07, 2021, 04:54:25 PM
Do you put the if option before the command.

exiftool -r -if '$Filename=~/_s\.tif/i' - FileName<${CreateDate;DateFmt("%Y%m%d")}_fadgi19264_$tNum_${CreateTime;DateFmt("%H%M")}_Start%.2nc.%e/"
Title: Re: find and renaming
Post by: StarGeek on December 07, 2021, 05:12:40 PM
As with nearly all exiftool options, it can appear anywhere in the command.  At the beginning, middle, or end, as long as it doesn't split a two part option such as the-TagsFromFile option (https://exiftool.org/exiftool_pod.html#tagsFromFile-SRCFILE-or-FMT) or the -p (-printFormat) option (https://exiftool.org/exiftool_pod.html#p-FMTFILE-or-STR--printFormat).
Title: Re: find and renaming
Post by: j99mac on December 08, 2021, 11:50:38 AM
I did some testing
with exiftool -r -if '$Filename=~/_s\.tif/i' '-FileName<FileModifyDate' -d %Y%m%d_#_%H%M_s.%%e
and get failed conditions

Do I need to add "" around '$Filename=~/_s\.tif/i' '-FileName<FileModifyDate' -d %Y%m%d_#_%H%M_s.%%e. ?
Title: Re: find and renaming
Post by: Phil Harvey on December 08, 2021, 12:32:17 PM
The command syntax looks good if you are on Mac.

Can you paste your exact command and the output for a single file that you think should pass the condition?

- Phil
Title: Re: find and renaming
Post by: j99mac on December 08, 2021, 12:35:20 PM
What if I want to run the command on multiple file in multiple folders named test
Title: Re: find and renaming
Post by: Phil Harvey on December 08, 2021, 12:43:17 PM
You should get it working on one file first.

Learn to walk before you run.

- Phil
Title: Re: find and renaming
Post by: j99mac on December 08, 2021, 12:48:42 PM
What if i want to run it on multiple directories and have it run on all finel with _s in files names. Would it work?
Title: Re: find and renaming
Post by: Phil Harvey on December 08, 2021, 12:54:21 PM
If it works on one file, it will work on many.
Title: Re: find and renaming
Post by: j99mac on December 08, 2021, 01:28:07 PM
is it posable to run the command on a bunch of directories at once?
Title: Re: find and renaming
Post by: Phil Harvey on December 08, 2021, 01:44:43 PM
Please read at least the first paragraph of the application documentation (https://exiftool.org/exiftool_pod.html#DESCRIPTION).
Title: Re: find and renaming
Post by: StarGeek on December 08, 2021, 01:49:45 PM
Quote from: j99mac on December 08, 2021, 11:50:38 AMDo I need to add ""

On a Mac, you want single quotes ' around any parameter that contains a dollar sign $.  See the text at the bottom of Phil's post.
Title: Re: find and renaming
Post by: j99mac on December 08, 2021, 02:21:41 PM
This is my command
exiftool -r -if '$Filename=~/_start\.tif/i' "-FileName<FileModifyDate" -d "%Y%m%d_fadgi19264_Model01_%H%M_start_g.%%e" (dir)


I ran it and now is there away to make "%Y%m%d" be the CreateDate? I am looking to get the created ate field in my filename.
I used this at one point {CreateDate;DateFmt("%Y%m%d")} and it worked with a single file.



Title: Re: find and renaming
Post by: StarGeek on December 08, 2021, 02:32:03 PM
CreateDate or FileCreateDate?

Also, you need a time component (HourMinuteSecond) in addition to YearMonthDay.  And where are you copying the time stamp from?

You really need to give more information in your posts and show what you've tried.  There's a limit to how helpful and patient I am when I have to keep asking question trying to figure out what you're doing.

Search the forums by using this Google link (https://www.google.com/search?q=site:exiftool.org).  Take time to read the documentation and FAQs.