Re-naming photo's

A swapping-ground for Regular Expression syntax

Re-naming photo's

Postby romprod » Mon Jul 15, 2019 2:07 pm

Hey Guys,

I've a bunch of photo's that I require renaming, I've had a look through the reg ex documents and my head starts to hurt everytime I try to figure it out!

So I'm wondering if you clever people can help out!


1:
Code: Select all
photo_1000@25-01-2016_20-35-35.jpg
to
25-01-2016_20-35-35.jpg

and
photo_101@05-07-2015_20-03-47.jpg
to
05-07-2015_20-03-47.jpg


So basically, remove everything prior to and including the @ sign.


2:
Change the date of the file from the filename (is this possible?)

All the files will be saved in this format, although there exists the possibility of multiple files that would have been renamed in the above step with the same filename for which BRU

Code: Select all
05-07-2015_20-03-47.jpg
or
05-07-2015_20-03-47_1.jpg
05-07-2015_20-03-47_2.jpg
romprod
 
Posts: 3
Joined: Thu Dec 29, 2016 4:18 pm

Re: Re-naming photo's

Postby therube » Mon Jul 15, 2019 8:52 pm

1.

1:RegEx:
Code: Select all
Match:  (.*?)@(.*)
Replace:  \2


Non-greedily match anything up to the first @, then match everything else.
Rename the file to the "everything else" part.


2.

Wasn't clear on what you were saying, but if you think you'll have potential duplicates on the rename, try, Renaming Options -> Prevent Duplicates.
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: Re-naming photo's

Postby romprod » Tue Jul 16, 2019 1:34 pm

Perfect thankyou, the first one did the trick.

What I'd like to do now is to set the files created/modified/accessed date and time by using the filename.

Each of the files are now named as below

01-03-2018_18-28-23.jpg

and any duplicates are named

01-03-2018_18-28-23_1.jpg

Is this possible?
romprod
 
Posts: 3
Joined: Thu Dec 29, 2016 4:18 pm

Re: Re-naming photo's

Postby therube » Sun Aug 18, 2019 6:30 pm

You could parse the filename, then send it to a Unix-like touch command.
Specifics are kind of beyond me, but something along these lines...


parse 01-03-2018_18-28-23.jpg to 01,03,2018 , 18,28,23
then rearrange things, 201801031828.23, setting that as a variable
then send that to touch

touch -t %variable% filename

So your command would end up being:
Code: Select all
touch.exe  -t  201801031828.23   01-03-2018_18-28-23.jpg

That would set the Modified & Accessed dates as specified.
(Created would be unchanged - at least in the version of touch that I use.)

Code: Select all
Usage: touch [OPTION]... FILE...
Update the access and modification times of each FILE to the current time.

Mandatory arguments to long options are mandatory for short options too.
  -a                     change only the access time
  -c, --no-create        do not create any files
  -d, --date=STRING      parse STRING and use it instead of current time
  -f                     (ignored)
  -m                     change only the modification time
  -r, --reference=FILE   use this file's times instead of current time
  -t STAMP               use [[CC]YY]MMDDhhmm[.ss] instead of current time
  --time=WORD            change the specified time:
                           WORD is access, atime, or use: equivalent to -a
                           WORD is modify or mtime: equivalent to -m
      --help     display this help and exit
      --version  output version information and exit

Note that the -d and -t options accept different time-date formats.

Report bugs to <bug-coreutils@gnu.org>.
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm


Return to Regular Expressions