Main Menu

find and renaming

Started by j99mac, October 28, 2021, 04:55:02 PM

Previous topic - Next topic

j99mac

is it posable to use a find and combidine it will renaming file?

StarGeek

I don't understand the question.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

j99mac

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

StarGeek

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 to pass the list to exiftool.

Basically, something like this if you were removing the _s part
exiftool "-Filename<${Filename;s/_s//}" -@ OutputFromFind.txt
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

j99mac

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/"

StarGeek

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.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

j99mac

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/"

Phil Harvey

You must specify the directory on the command line.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

j99mac

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

j99mac

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

StarGeek

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 and Common Mistake #2c.

You'll have to filter using the -if option and RegEx.  For example
-if '$Filename=~/_finsh.tif/'
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

j99mac

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/"

StarGeek

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 or the -p (-printFormat) option.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

j99mac

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. ?

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).