Giter Site home page Giter Site logo

ayoisaiah / f2 Goto Github PK

View Code? Open in Web Editor NEW
803.0 9.0 36.0 52.58 MB

F2 is a cross-platform command-line tool for batch renaming files and directories quickly and safely. Written in Go!

License: MIT License

Go 96.66% Shell 3.22% Just 0.13%
golang bulk-rename-files macos windows linux rename-files batch-rename

f2's People

Contributors

ayoisaiah avatar d-rickyy-b avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

f2's Issues

[bug] auto make directory failed (windows os)

  • a file named as video file from internet [youtube][id][uploader] - part 2.mp4 in R:\ (windows drive root path)
  • i'd like to rename/move it into a sub folder named [uploader]
  • the f2 command used was f2 -f "^(.*(\[.+?\]).*?)$" -r "$2\$1" -x R:\
  • f2 error was An error occurred while renaming 'R:\video file from internet [youtube][id][uploader] - part 2.mp4' to 'R:\[uploader]\video file from internet [youtube][id][uploader] - part 2.mp4'
  • it did try to rename it with prefix path of parent R:\[uploader]\, but this sub folder/directory wasn't there

not sure if it's windows os specific bug
maybe the windows path sep backslash \ is the cause?

How to batch pad 0 of number ?

Files in the current directory:
1.txt 22.txt 333.txt
1.txt -> 0001.txt
22.txt -> 0022.txt
333.txt -> 0333.txt
With another command line rename tool nomino:
nomino -tp "([0-9]+).txt" "{:4}.txt"
Since it is a very common task.
How to do this with f2 ?

x.cdt return None on some old image,exiftool shows DateTimeOriginal

when i rename some old pictures, x.cdt return None on most of them when exiftool shows DateTimeOriginal as normal
is there something i missing?

$ f2  -r '{x.cdt.YYYY}{x.cdt.MM}{x.cdt.DD}/{x.cdt.YYYY}{x.cdt.MM}{x.cdt.DD}-{x.cdt.H}{x.cdt.mm}{x.cdt.ss}_{x.model}_{%03d}{ext}'
┌─────────────────────────────────────────────────────────────┐
| ORIGINAL     | RENAMED                             | STATUS |
| *********************************************************** |
| 14090010.jpg | 20140918\20140918-072445_N9_001.jpg | ok     |
| 14090011.jpg | 20140918\20140918-074600_N9_002.jpg | ok     |
| 14090012.jpg | -_N9_003.jpg                        | ok     |
| 14090013.jpg | -_N9_004.jpg                        | ok     |
└─────────────────────────────────────────────────────────────┘
 DRY RUN  Commit the above changes with the -x/--exec flag

$ exiftool.exe 14090010.jpg
ExifTool Version Number         : 12.57
File Name                       : 14090010.jpg
Directory                       : .
File Size                       : 1218 kB
File Modification Date/Time     : 2014:09:17 23:24:48+08:00
File Access Date/Time           : 2023:03:12 22:54:04+08:00
File Creation Date/Time         : 2023:03:12 22:54:04+08:00
File Permissions                : -rw-rw-rw-
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
Exif Byte Order                 : Little-endian (Intel, II)
Make                            : Nokia
Camera Model Name               : N9
Modify Date                     : 2014:09:18 07:24:45
Exposure Time                   : 1/333
F Number                        : 2.2
Exposure Program                : Not Defined
ISO                             : 100
Exif Version                    : 0230
Date/Time Original              : 2014:09:18 07:24:45
Shutter Speed Value             : 1/333
Aperture Value                  : 2.2
Exposure Compensation           : 0
Metering Mode                   : Average
Flash                           : Auto, Did not fire
Focal Length                    : 28.0 mm
Warning                         : [minor] Unrecognized MakerNotes
Flashpix Version                : 0100
File Source                     : Digital Camera
Sensitivity Type                : ISO Speed
ISO Speed                       : 100
Exposure Mode                   : Auto
White Balance                   : Auto
Digital Zoom Ratio              : 1
Scene Capture Type              : Standard
Gain Control                    : None
Contrast                        : Normal
Saturation                      : Normal
Sharpness                       : Normal
XMP Toolkit                     : GStreamer
Orientation                     : Rotate 90 CW
Image Width                     : 2000
Image Height                    : 3552
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Aperture                        : 2.2
Image Size                      : 2000x3552
Megapixels                      : 7.1
Shutter Speed                   : 1/333
Focal Length                    : 28.0 mm
Light Value                     : 10.7
$ exiftool.exe 14090012.jpg
ExifTool Version Number         : 12.57
File Name                       : 14090012.jpg
Directory                       : .
File Size                       : 1160 kB
File Modification Date/Time     : 2014:09:18 17:02:46+08:00
File Access Date/Time           : 2023:03:12 22:54:04+08:00
File Creation Date/Time         : 2023:03:12 22:54:04+08:00
File Permissions                : -rw-rw-rw-
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
JFIF Version                    : 1.01
Resolution Unit                 : inches
X Resolution                    : 96
Y Resolution                    : 96
Exif Byte Order                 : Big-endian (Motorola, MM)
Make                            : Nokia
Camera Model Name               : N9
Orientation                     : Horizontal (normal)
Software                        : Microsoft Windows Photo Viewer 6.1.7600.16385
Modify Date                     : 2014:09:18 17:02:41
Exposure Time                   : 1/1000
F Number                        : 2.2
Exposure Program                : Not Defined
ISO                             : 100
Sensitivity Type                : ISO Speed
ISO Speed                       : 100
Exif Version                    : 0230
Date/Time Original              : 2014:09:18 07:47:05
Shutter Speed Value             : 1/1000
Aperture Value                  : 2.2
Exposure Compensation           : 0
Metering Mode                   : Average
Flash                           : Auto, Did not fire
Focal Length                    : 28.0 mm
Warning                         : [minor] Unrecognized MakerNotes
Flashpix Version                : 0100
File Source                     : Digital Camera
Exposure Mode                   : Auto
White Balance                   : Auto
Digital Zoom Ratio              : 1
Scene Capture Type              : Standard
Gain Control                    : None
Contrast                        : Normal
Saturation                      : Normal
Sharpness                       : Normal
Offset Schema                   : 4218
Padding                         : (Binary data 2060 bytes, use -b option to extract)
XMP Toolkit                     : GStreamer
Creator Tool                    : Microsoft Windows Photo Viewer 6.1.7600.16385
Image Width                     : 2000
Image Height                    : 3552
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Aperture                        : 2.2
Image Size                      : 2000x3552
Megapixels                      : 7.1
Shutter Speed                   : 1/1000
Focal Length                    : 28.0 mm
Light Value                     : 12.2

fail.zip

String functions usage enhancements

I would suggest couple of enhancements to this great tool!

  1. allow string functions to be used on match groups, e.g.: f2 '\b(.)' '{{$1.up}}'
  2. allow string transformations to be used on built in variables: e.g.: f2 '.*' '{{f.ti}}{{ext}}'

on Windows command prompt using single quote do not work

Hello

Just a remark, on command prompt for windows the single quote do not work :)

as it was my first time playing with f2, it toook some time to get it working (with command line binary, i test first on cmd, before going to powershell, old habit)

it's just maybe in the wiki a tiny warning :)

thanks for your work.

Tonic8

Version of F2: 1.6.5_amd64
OS: windows 10 20H2

using the command with single quote it's not working on a CMD prompt

C:\Temp\test>f2.exe -f '.cbr' -r '.rar'
Failed to match any files

while doing the same command with double quotes work on a CMD prompt

C:\Temp\test>f2.exe -f ".cbr" -r ".rar"

+-----------+-----------+--------+
|   INPUT   |  OUTPUT   | STATUS |
+-----------+-----------+--------+
| test1.cbr | test1.rar | ok     |
+-----------+-----------+--------+
Append the -x flag to apply the above changes

the same with REGEX on a CMD prompt

C:\Temp\test>f2.exe -f '\(2021\)' -r '[2022]'
Failed to match any files

C:\Temp\test>f2.exe -f "\(2021\)" -r "[2022]"
+--------------------------------------+--------------------------------------+--------+
|                INPUT                 |                OUTPUT                | STATUS |
+--------------------------------------+--------------------------------------+--------+
| No Pressure (2021) S01.E01.2160p.mp4 | No Pressure [2022] S01.E01.2160p.mp4 | ok     |
+--------------------------------------+--------------------------------------+--------+
Append the -x flag to apply the above changes

with a simple DIR the single quote do not work

C:\Temp\test>dir
 Le volume dans le lecteur C n’a pas de nom.
 Le numéro de série du volume est CCB8-8D6F

 Répertoire de C:\Temp\test

29/05/2021  17:34    <DIR>          .
29/05/2021  17:34    <DIR>          ..
29/05/2021  17:34                 0 No Pressure (2021) S01.E01.2160p.mp4
29/05/2021  17:28                 0 test1.cbr
29/05/2021  17:28                 0 test2.cbz
               3 fichier(s)                0 octets
               2 Rép(s)  101 577 428 992 octets libres

C:\Temp\test>dir 'test1.cbr'
 Le volume dans le lecteur C n’a pas de nom.
 Le numéro de série du volume est CCB8-8D6F

 Répertoire de C:\Temp\test

Fichier introuvable

C:\Temp\test>dir "test1.cbr"
 Le volume dans le lecteur C n’a pas de nom.
 Le numéro de série du volume est CCB8-8D6F

 Répertoire de C:\Temp\test

29/05/2021  17:28                 0 test1.cbr
               1 fichier(s)                0 octets
               0 Rép(s)  101 575 655 424 octets libres

this behaviour do not exist on powershell

PS C:\Temp\test> f2.exe -f '.cbr' -r '.rar'
+-----------+-----------+--------+
|   INPUT   |  OUTPUT   | STATUS |
+-----------+-----------+--------+
| test1.cbr | test1.rar | ok     |
+-----------+-----------+--------+
Append the -x flag to apply the above changes
PS C:\Temp\test> f2.exe -f ".cbr" -r ".rar"
+-----------+-----------+--------+
|   INPUT   |  OUTPUT   | STATUS |
+-----------+-----------+--------+
| test1.cbr | test1.rar | ok     |
+-----------+-----------+--------+
Append the -x flag to apply the above changes

Renaming mp3s fails on Windows if using ID3 tags.

Trying to rename a folder full of mp3 on Windows 10 using ID3 tags results in the following error for every file:
The process cannot access the file because it is being used by another process.
Using a file handle viewer, I was able to conclude that no processes actually had the files open and by trial and error, I discovered that it was the use of ID3 tags to rename it that was causing the error.
f2 -r "{{id3.artist}} - {{id3.title}}{{ext}}" -x

[bug] error when double dots ".." in sub-folder (of dst path)

I'm using f2 to group lots of files into sub-folders based on part of their names, via regex. When renameing is something like from src /root/title [artist_name_with..].mp4 to dst /root/artist_name_with../title [artist_name_with..].mp4, it throws an error occurred while renaming. Could only guess but seems like the double dots .. in the sub-folder name artist_name_with.. is the cause.

OS is Windows 10

Not working with basic regex?

I had high hopes for this tool but unless I am entirely misreading stuff basic regex does not work..

maikocosta@Maikos-Mac fromOO % f2 --version F2 version v1.9.1 https://github.com/ayoisaiah/f2/releases/v1.9.1

one of the many files that f2 does nothing recognizable

maikocosta@Maikos-Mac fromOO % file Umwelt/Done/87_Internet\ Telenor\ \#w38

Umwelt/Done/87_Internet Telenor #w38: directory
maikocosta@Maikos-Mac fromOO % f2 -f 'Internet' -R

*————————————————————————————————*————————————————————————————————*————————*
|            ORIGINAL            |            RENAMED             | STATUS |
*————————————————————————————————*————————————————————————————————*————————*
| Umwelt/Done/87_Internet        | Umwelt/Done/87_Internet        | ok     |
| Telenor #w38/Internet Telenor  | Telenor #w38/Telenor #w38.md   |        |
| #w38.md                        |                                |        |
*————————————————————————————————*————————————————————————————————*————————*



 DRY RUN  Commit the above changes with the -x/--exec flag

maikocosta@Maikos-Mac fromOO % f2 -f '87_Internet' -R
 INFO  Failed to match any files

maikocosta@Maikos-Mac fromOO % f2 -f '_Internet' -R 
 INFO  Failed to match any files

maikocosta@Maikos-Mac fromOO % f2 -f '87_' -R      
 INFO  Failed to match any files
maikocosta@Maikos-Mac fromOO % f2 -f '\/[0-9]+_' -R
 INFO  Failed to match any files

Am I missing something here?

RFE: Avoid cluttering $HOME, move config files/data to their appropriate place.

Short description:
f2 writes to $HOME/.f2

What is wrong with this?
If all programs would write to $HOME, one would end up with $HOME full of dot files/dirs. This not only leads to cutter, but makes it difficult for backup. There are also folks who manage their $HOME or part(s) of it with git. So if apps write non important stuff directly to $HOME, you can imagine how many changes git would report. One would also backup this stuff. Their exists a standard that defines where an application should save {config, temporary, cache,...} files. For more information have a look at XDG spec.

Solution:
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

Go implementations of the the spec (random):
https://github.com/adrg/xdg
https://github.com/rkoesters/xdg

F2 version v1.6.7

exiftool - fatal error: all goroutines are asleep - deadlock

As I was trying to use the exiftool, it seems that I broke your tool (again) :D. I am using Windows and installed the exiftool via chocolatey (choco install exiftool). Maybe It's because of the way I installed exiftool. Are there instructions for installing exiftool on Windows?

PS > f2 -r '{{xt.Title}} by {{xt.Creator}}{{ext}}'
fatal error: all goroutines are asleep - deadlock!

goroutine 1 [select]:
io.(*pipe).read(0xc00002a300, {0xc00014106f, 0xf91, 0x9?})
        C:/Program Files/Go/src/io/pipe.go:57 +0xb1
io.(*PipeReader).Read(0xc000141000?, {0xc00014106f?, 0x1000?, 0x201300?})
        C:/Program Files/Go/src/io/pipe.go:136 +0x25
bufio.(*Scanner).Scan(0xc00009b980)
        C:/Program Files/Go/src/bufio/scan.go:214 +0x876
github.com/barasher/go-exiftool.(*Exiftool).ExtractMetadata(0xc000136fc0, {0xc00010f2f8, 0x1, 0xc00010f250?})
        C:/Users/Rico/go/pkg/mod/github.com/barasher/[email protected]/exiftool.go:131 +0x3d6
github.com/ayoisaiah/f2/src.replaceExifToolVariables({0xc000010cf0, 0x22}, {0xc000016d68, 0x12}, {{0xc000162000, 0x2, 0xa}, {0xc0000f16e0, 0x2, 0x2}})
        C:/Users/Rico/go/pkg/mod/github.com/ayoisaiah/[email protected]/src/variables.go:666 +0xfc
github.com/ayoisaiah/f2/src.(*Operation).replaceVariables(0xc000049a00, 0xc00010f838, 0xc00010f908)
        C:/Users/Rico/go/pkg/mod/github.com/ayoisaiah/[email protected]/src/variables.go:884 +0x4ef
github.com/ayoisaiah/f2/src.(*Operation).replace(0xc000049a00)
        C:/Users/Rico/go/pkg/mod/github.com/ayoisaiah/[email protected]/src/replace.go:643 +0x23a
github.com/ayoisaiah/f2/src.(*Operation).handleReplacementChain(0xc000049a00)
        C:/Users/Rico/go/pkg/mod/github.com/ayoisaiah/[email protected]/src/operation.go:572 +0x9e
github.com/ayoisaiah/f2/src.(*Operation).run(0xc000049a00)
        C:/Users/Rico/go/pkg/mod/github.com/ayoisaiah/[email protected]/src/operation.go:632 +0xaf
github.com/ayoisaiah/f2/src.newApp.func1(0xc000061740)
        C:/Users/Rico/go/pkg/mod/github.com/ayoisaiah/[email protected]/src/app.go:359 +0x2c9
github.com/urfave/cli/v2.(*App).RunContext(0xc00013e000, {0x68c530?, 0xc00000e0d0}, {0xc000060040, 0x3, 0x4})
        C:/Users/Rico/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:315 +0x9f5
github.com/urfave/cli/v2.(*App).Run(...)
        C:/Users/Rico/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:215
main.main()
        C:/Users/Rico/go/pkg/mod/github.com/ayoisaiah/[email protected]/cmd/f2/main.go:14 +0x65

[discuss] should "Failed to match any files" be handled as an error or just a warning?

it is the exit code that matters
since f2 doesn't match any file, then setting the exit code to 1 is kind of "improper", and will disturb the following processes in a running script - case the script needs to check if f2 encountered any real error to determine how to do the next step
maybe just print that warning line, but without set the exit code, how's that?

Leading zeros

I'm using

f2 -f '(\w+) ((\d+)).(\w+)' -r '$1-$2.$3'

and get

| ORIGINAL | RENAMED | STATUS |
| ************************************************ |
| 1528655011 (1).jpg | 1528655011-1.jpg | ok |
| 1528655011 (10).jpg | 1528655011-10.jpg | ok |

but I want for $2 leading zeros and 3 digits.

How I have to do it?

Piping output to f2 doesn't work as expected

Perhaps I am doing it wrong, but: fd -e jpg 'IMG' | f2 -r '{{x.dt.YYYY}}-{{x.dt.MM}}-{{x.dt.DD}}-{{x.dt.H}}-{{x.dt.mm}}-{{x.dt.ss}}_{{x.make}}-{{x.model}}-%07d' yields: INFO Failed to match any files.

Which is kind of unexpected since fd --change-newer-than '2020-04-01 00:00:00' | f2 -r '{{mtime.YYYY}}-{{mtime.MM}}-{{mtime.DD}}_{{f}}' -e --sortr 'mtime' from https://github.com/ayoisaiah/f2/wiki/Renaming-recipes#usage-with-fd does work.

If I manually provide the filename like this: f2 -r '{{x.dt.YYYY}}-{{x.dt.MM}}-{{x.dt.DD}}-{{x.dt.H}}-{{x.dt.mm}}-{{x.dt.ss}}_{{x.make}}-{{x.model}}-%07d' ./2022-10-15/IMG_20221015_113141581.jpg. Then it works:

❯ f2 -r '{{x.dt.YYYY}}-{{x.dt.MM}}-{{x.dt.DD}}-{{x.dt.H}}-{{x.dt.mm}}-{{x.dt.ss}}_{{x.make}}-{{x.model}}-%07d' ./2022-10-15/IMG_20221015_113141581.jpg
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
| ORIGINAL                              | RENAMED                                                         | STATUS |
| **************************************************************************************************************** |
| 2022-10-15/IMG_20221015_113141581.jpg | 2022-10-15/2022-10-15-11-31-43_motorola-moto g(8) power-0000001 | ok     |
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

What am I doing wrong?

Using regex capture group appended with underscore leads to erroneously named files

Hi and thank you for creating this awesome tool!

I ran into an issue where f2 doesn't generate the desired output name when using regex capture groups together with an underscore.

Steps to reproduce

I created a test directory with three test files. In there I tried to rename the test1.txt to test_01.txt.

PS > touch test1.txt
PS > touch test2.txt
PS > touch test3.txt
PS > f2 -f '(.*)\d.txt' -r '$1_%02d{{ext}}'

Expected result

I assumed that the files would get renamed to test_01.txt, etc. Something like this:

┌──────────────────────────────────┐
| ORIGINAL  | RENAMED     | STATUS |
| ******************************** |
| test1.txt | test_01.txt | ok     |
| test2.txt | test_02.txt | ok     |
| test3.txt | test_03.txt | ok     |
└──────────────────────────────────┘

Actual result

Actually the tool is not happy about the _ and does not insert the first capture group at all.

┌──────────────────────────────┐
| ORIGINAL  | RENAMED | STATUS |
| **************************** |
| test1.txt | 01.txt  | ok     |
| test2.txt | 02.txt  | ok     |
| test3.txt | 03.txt  | ok     |
└──────────────────────────────┘

The error becomes more obvious when using the following command: f2 -V -f '(.*)\d.txt' -r '$1_a'

┌──────────────────────────────────────┐
| ORIGINAL  | RENAMED | STATUS         |
| ************************************ |
| test1.txt |         | empty filename |
| test2.txt |         | empty filename |
| test3.txt |         | empty filename |
└──────────────────────────────────────┘

Without the underscore it works just fine f2 -V -f '(.*)\d.txt' -r '$1 %02d{{ext}}'

┌──────────────────────────────────┐
| ORIGINAL  | RENAMED     | STATUS |
| ******************************** |
| test1.txt | test 01.txt | ok     |
| test2.txt | test 02.txt | ok     |
| test3.txt | test 03.txt | ok     |
| test4.txt | test 04.txt | ok     |
└──────────────────────────────────┘

Version

PS > f2 --version
f2 version v1.8.0
https://github.com/ayoisaiah/f2/releases/v1.8.0

Let me know if you need anything else in order to further investigate the issue.

Cheers,
Rico

Extract date and time from video files

Hi,

I was trying to sort out my media files, and I've noticed that f2 doesn't really support reading date and time reading from a mp4 file. They don't have the usual date time field used for photos but have MediaCreateDate:

[{
  "SourceFile": "testdata/videos/pixel6pro.mp4",
  "ExifToolVersion": 11.88,
  "FileName": "pixel6pro.mp4",
  "Directory": "testdata/videos",
  "FileSize": "15 MB",
  "FileModifyDate": "2022:10:24 03:46:40+02:00",
  "FileAccessDate": "2022:10:24 17:24:54+02:00",
  "FileInodeChangeDate": "2022:10:24 17:50:10+02:00",
  "FilePermissions": "rwxrwxrwx",
  "FileType": "MP4",
  "FileTypeExtension": "mp4",
  "MIMEType": "video/mp4",
  "MajorBrand": "MP4  Base Media v1 [IS0 14496-12:2003]",
  "MinorVersion": "2.0.0",
  "CompatibleBrands": ["isom","iso2","mp41"],
  "MediaDataSize": 15765030,
  "MediaDataOffset": 44,
  "MovieHeaderVersion": 0,
  "CreateDate": "2022:10:21 15:58:43",
  "ModifyDate": "2022:10:21 15:58:43",
  "TimeScale": 10000,
  "Duration": "8.01 s",
  "PreferredRate": 1,
  "PreferredVolume": "100.00%",
  "PreviewTime": "0 s",
  "PreviewDuration": "0 s",
  "PosterTime": "0 s",
  "SelectionTime": "0 s",
  "SelectionDuration": "0 s",
  "CurrentTime": "0 s",
  "NextTrackID": 6,
  "GPSCoordinates": "40 deg 42' 43.56\" N, 74 deg 0' 42.48\" W",
  "TrackHeaderVersion": 0,
  "TrackCreateDate": "2022:10:21 15:58:43",
  "TrackModifyDate": "2022:10:21 15:58:43",
  "TrackID": 1,
  "TrackDuration": "8.01 s",
  "TrackLayer": 0,
  "TrackVolume": "100.00%",
  "ImageWidth": 1024,
  "ImageHeight": 768,
  "GraphicsMode": "srcCopy",
  "OpColor": "0 0 0",
  "CompressorID": "avc1",
  "SourceImageWidth": 1024,
  "SourceImageHeight": 768,
  "XResolution": 72,
  "YResolution": 72,
  "BitDepth": 24,
  "PixelAspectRatio": "65536:65536",
  "ColorRepresentation": "nclx 1 1 1",
  "VideoFrameRate": 24.233,
  "Warning": "[minor] The ExtractEmbedded option may find more tags in the media data",
  "Balance": 0,
  "AudioFormat": "mp4a",
  "AudioChannels": 2,
  "AudioBitsPerSample": 16,
  "AudioSampleRate": 48000,
  "MatrixStructure": "0 1 0 -1 0 0 0 0 1",
  "MediaHeaderVersion": 0,
  "MediaCreateDate": "2022:10:21 15:58:43",
  "MediaModifyDate": "2022:10:21 15:58:43",
  "MediaTimeScale": 90000,
  "MediaDuration": "0 s",
  "HandlerType": "NRT Metadata",
  "HandlerDescription": "MetaHandle",
  "MetaFormat": "mett",
  "ImageSize": "1024x768",
  "Megapixels": 0.786,
  "AvgBitrate": "15.7 Mbps",
  "GPSLatitude": "40 deg 42' 43.56\" N",
  "GPSLongitude": "74 deg 0' 42.48\" W",
  "Rotation": 90,
  "GPSPosition": "40 deg 42' 43.56\" N, 74 deg 0' 42.48\" W"
}]

so technically it should be able to extract this value, parse it and make it accessible via x.dt.YYYY for example. What do you think?

I could use xt.MediaCreateDate but it's hard to parse it to something like 2022-10-24_18-33 because it uses : inside of the string

Regular expressions

Does the use of regular expressions require Go to be installed?

$ f2 -f ((.*?)) -r '-'
bash: syntax error near unexpected token `('

Thank you

not working for me!

Hi there,

I found your app tonight while testing multiple cli regex batch renaming tools.

In the first place it was very convincing but it didn't work for me.

I have file names like:
Rechnung_01_2023_30071007000721.pdf
Rechnung_02_2023_30071007000721.pdf
Rechnung_03_2023_30071007000721.pdf
Rechnung_04_2023_30071007000721.pdf
Rechnung_05_2023_30071007000721.pdf

I tested my regex on https://regex101.com/ for matching "(\d{2})(\d{4})" and replacing it by "$2$1".

I'm sure this is a very basic operation, but I don't know why your app doesn't produce the expected output?!

My command line looks like:
D:!data\documents\telekom 2022-10-10\2023>"c:!data\pc-game\Desktop\f2_1.9.0_windows_amd64.tar\f2.exe" -f "(\d{2})(\d{4})" -r "$2$1"

and the result is missing $2:
┌───────────────────────────────────────────────────────────────────────────────┐
| ORIGINAL | RENAMED | STATUS |
| ***************************************************************************** |
| Rechnung_01_2023_30071007000721.pdf | Rechnung_01_30071007000721.pdf | ok |
| Rechnung_02_2023_30182074000721.pdf | Rechnung_02_30182074000721.pdf | ok |
| Rechnung_03_2023_30289101000721.pdf | Rechnung_03_30289101000721.pdf | ok |
| Rechnung_04_2023_30399641000721.pdf | Rechnung_04_30399641000721.pdf | ok |
| Rechnung_05_2023_30508276000721.pdf | Rechnung_05_30508276000721.pdf | ok |
| Rechnung_06_2023_30731561000721.pdf | Rechnung_06_30731561000721.pdf | ok |
└───────────────────────────────────────────────────────────────────────────────┘

The command line:
D:!data\documents\telekom 2022-10-10\2023>"c:!data\pc-game\Desktop\f2_1.9.0_windows_amd64.tar\f2.exe" -f "(\d{2})_(\d{4})" -r "$2-$1"
works well with the expected output:
┌────────────────────────────────────────────────────────────────────────────────────┐
| ORIGINAL | RENAMED | STATUS |
| ********************************************************************************** |
| Rechnung_01_2023_30071007000721.pdf | Rechnung_2023-01_30071007000721.pdf | ok |
| Rechnung_02_2023_30182074000721.pdf | Rechnung_2023-02_30182074000721.pdf | ok |
| Rechnung_03_2023_30289101000721.pdf | Rechnung_2023-03_30289101000721.pdf | ok |
| Rechnung_04_2023_30399641000721.pdf | Rechnung_2023-04_30399641000721.pdf | ok |
| Rechnung_05_2023_30508276000721.pdf | Rechnung_2023-05_30508276000721.pdf | ok |
| Rechnung_06_2023_30731561000721.pdf | Rechnung_2023-06_30731561000721.pdf | ok |
└────────────────────────────────────────────────────────────────────────────────────┘

But I don't want the dash as separator. I want the underscore and it doesn't work for it?!
I tried to escape it by "$2_$1" but that didn't work too.

So, what am I doing wrong?

Fun fact, this exact behavior is reproduced by brenamer ... coincidence? or using some common libraries??

Best regards,
Teo

"-e" option considers the last period in directory name as extension separator

For example, if I have directory test.dir.period nested inside test directory, then running f2 -ed -f '\.' -r ' ' test returns this:

+----------------------+----------------------+--------+
|        INPUT         |        OUTPUT        | STATUS |
+----------------------+----------------------+--------+
| test/test.dir.period | test/test dir.period | ok     |
+----------------------+----------------------+--------+

And if I try to match the "extension" of the directory by running f2 -ed -f 'period' -r 'full stop' test:
INFO Failed to match any files

Version: 1.7.2
OS: Arch Linux

Installation is not supported for this architecture: arm64

I am using a Mac Silicon Mx chip. I couldn't install F2 please help

$ npm i @ayoisaiah/f2 -g                                                                                                                                                                                                                         ~
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated [email protected]: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
npm ERR! code 1
npm ERR! path /opt/homebrew/lib/node_modules/@ayoisaiah/f2
npm ERR! command failed
npm ERR! command sh -c go-npm install
npm ERR! Installation is not supported for this architecture: arm64
npm ERR! Invalid inputs

npm ERR! A complete log of this run can be found in:

issue on New feature (from 1.6.4 multiple renaming in the same command line

Hello

on 1.6.4 release the new feature, seems to not work (or i'm badly trying to use it :) )

You can now chain several renaming operations by specifying the --find and --replace flags multiple times.

in the below example i'm trying to rename all cbr/cbz files to rar/zip, but the command result on the first -find -replace in the command line

C:\Temp\test>dir
 Le volume dans le lecteur C n’a pas de nom.
 Le numéro de série du volume est CCB8-8D6F

 Répertoire de C:\Temp\test

29/05/2021  17:34                 0 No Pressure (2021) S01.E01.2160p.mp4
29/05/2021  17:28                 0 test1.cbr
29/05/2021  17:28                 0 test2.cbz

C:\Temp\test>D:\Workspace\Dev\optimize-file\Modules\f2\f2.exe -f ".cbz" -r ".zip" -f ".cbr" -r ".rar" -i -s C:\Temp\test\
+------------------------+------------------------+--------+
|         INPUT          |         OUTPUT         | STATUS |
+------------------------+------------------------+--------+
| C:\Temp\test\test2.cbz | C:\Temp\test\test2.zip | ok     |
+------------------------+------------------------+--------+
Append the -x flag to apply the above changes

C:\Temp\test>D:\Workspace\Dev\optimize-file\Modules\f2\f2.exe --find ".cbr" --replace ".rar" --find ".cbz" --replace ".zip" -i -s C:\Temp\test\
+------------------------+------------------------+--------+
|         INPUT          |         OUTPUT         | STATUS |
+------------------------+------------------------+--------+
| C:\Temp\test\test1.cbr | C:\Temp\test\test1.rar | ok     |
+------------------------+------------------------+--------+
Append the -x flag to apply the above changes

tested with 1.6.5 and 1.6.4
OS: windows 10 20H2

any suggestion on the right way to use it?

many thanks
Tonic8

Installation and usage instructions for Termux/Android

Hi there,

after I switched phones recently, all my "last modified" timestamps of my images were set to a wrong date which means images don't show up in the correct order. Now I wanted to use f2 to fix that issue. Sadly Windows does not allow command line access to the phone, so I checked alternatives and saw that you offer a termux/Android version.

Since I have never used external software with termux, I was a bit stuck. An entry in the wiki page for installation would probably help newcomers find what they need. Also it would be a nice addition to the otherwise already excellent wiki you have for this project.

Looking forward to hearing from you.

Rico

PS: I solved the initial issue with the timestamps as follows:

$ for name in IMG_[0-9]*.mp4; do touch -t ${name:4:8}${name:13:4}.${name:17:2} "$name"; done
$ for name in VID_[0-9]*.mp4; do touch -t ${name:4:8}${name:13:4}.${name:17:2} "$name"; done

[Help] How to match ISO date string

I would like to be able to replace the filenames of multiple files without changing the date/time.

So I have files with multiples dates and times like:

2023-02-23 Filename.pdf | 2023-02-27T16.10.34 Filename.pdf

I want to maintain the date/date-time and rename only the 'Filename'. So:

2023-02-23 NewFilename.pdf | 2023-02-27T16.10.34 NewFilename.pdf

Passing options to ExifTool

I tried using f2 -f '.*.mp4' -r '{{xt.MediaCreateDate}}{{ext}}' -f ':' -r '-' -f ' ' -r '_' to process my video files but one of the files apparently had no MediaCreateDate set.

Manually inspecting the file using exiftool yielded

❯ exiftool 2022-04-24/2022-04-24-12-31-09-0000531.mp4
ExifTool Version Number         : 11.88
File Name                       : 2022-04-24-12-31-09-0000531.mp4
Directory                       : 2022-04-24
File Size                       : 2.4 GB
File Modification Date/Time     : 2022:10:24 02:40:46+02:00
File Access Date/Time           : 2022:10:24 18:46:02+02:00
File Inode Change Date/Time     : 2022:10:24 18:43:11+02:00
File Permissions                : rwxrwxrwx
File Type                       : MP4
File Type Extension             : mp4
MIME Type                       : video/mp4
Major Brand                     : MP4  Base Media v1 [IS0 14496-12:2003]
Minor Version                   : 2.0.0
Compatible Brands               : isom, iso2, mp41
Warning                         : End of processing at large atom (LargeFileSupport not enabled)

Turns out, you can enable it by addding -api LargeFileSupport=1 to the command line:

❯ exiftool -api LargeFileSupport=1 2022-04-24/2022-04-24-12-31-09-0000531.mp4
Media Create Date               : 2022:04:24 10:31:09
Media Modify Date               : 2022:04:24 10:31:09

Can we make this LargeFileSupport an optional flag or something?

f2 phones home to Microsoft leaking my IP as an f2 user without consent when I run `f2 --version`

Behavior reproduced in F2 version v1.7.2:

f2/src/app.go

Line 149 in 134ae1e

resp, err := c.Get("https://github.com/ayoisaiah/f2/releases/latest")

Steps to reproduce:

  1. Run f2 --version.

Observed behavior:

F2 phones home to Microsoft without consent, leaking my IP to Microsoft as a user of F2 (enabling tracking):

Screen Shot 2022-02-01 at 21 56 20

Expected behavior:

The software would ask opt-in permission before leaking my usage activity and IP to giant multinationals.

Data loss due to issue with --fix-conflicts

Hi there, it's me again.

I just experienced a bug where the -F switch lead to data loss. For whatever reason f2 decided that it is totally okay to rename two files to the same name. Obviously it wasn't able to recover from this issue, since the source file wasn't there anymore.
Luckily I already anticipated this behavior, so I copied the data to a different folder to test this beforehand.

PS Y:\> f2 --version
f2 version v1.9.0
https://github.com/ayoisaiah/f2/releases/v1.9.0

PS Y:\> f2 -f ".*\.(jpg|JPG)" -r 'IMG_{x.cdt.YYYY}{x.cdt.MM}{x.cdt.DD}_{x.cdt.H}{x.cdt.mm}{x.cdt.ss}.jpg'
┌───────────────────────────────────────────────────────────────────────────┐
| ORIGINAL       | RENAMED                 | STATUS                         |
| ************************************************************************* |
| 116_1009-1.jpg | IMG_20080330_170816.jpg | overwriting newly renamed path |
| 116_1009.JPG   | IMG_20080330_170816.jpg | overwriting newly renamed path |
| 116_0990-1.jpg | IMG_20080328_125817.jpg | overwriting newly renamed path |
| 116_0990.JPG   | IMG_20080328_125817.jpg | overwriting newly renamed path |
└───────────────────────────────────────────────────────────────────────────┘
 ERROR  resolve conflicts before proceeding or use -F/--fix-conflicts to auto-fix

PS Y:\> f2 -f ".*\.(jpg|JPG)" -r 'IMG_{x.cdt.YYYY}{x.cdt.MM}{x.cdt.DD}_{x.cdt.H}{x.cdt.mm}{x.cdt.ss}.jpg' -F
┌───────────────────────────────────────────────────────┐
| ORIGINAL       | RENAMED                     | STATUS |
| ***************************************************** |
| 116_0990-1.jpg | IMG_20080328_125817.jpg     | ok     |
| 116_0990.JPG   | IMG_20080328_125817 (2).jpg | ok     |
| 116_1009-1.jpg | IMG_20080330_170816.jpg     | ok     |
| 116_1009.JPG   | IMG_20080330_170816.jpg     | ok     |
└───────────────────────────────────────────────────────┘
 DRY RUN  Commit the above changes with the -x/--exec flag

PS Y:\> f2 -f ".*\.(jpg|JPG)" -r 'IMG_{x.cdt.YYYY}{x.cdt.MM}{x.cdt.DD}_{x.cdt.H}{x.cdt.mm}{x.cdt.ss}.jpg' -F -x

PS Y:\> f2 -ux
┌───────────────────────────────────────────────────────────────────────────────────────────┐
| ORIGINAL                    | RENAMED        | STATUS                                     |
| ***************************************************************************************** |
| IMG_20080328_125817.jpg     | 116_0990-1.jpg | ok                                         |
| IMG_20080328_125817 (2).jpg | 116_0990.JPG   | ok                                         |
| IMG_20080330_170816.jpg     | 116_1009.JPG   | ok                                         |
| IMG_20080330_170816.jpg     | 116_1009-1.jpg | The system cannot find the file specified. |
└───────────────────────────────────────────────────────────────────────────────────────────┘
 ERROR  reverting the renaming operation failed due to the above errors

PS Y:\>

Do you have an idea why this might be happening?

Fail to replace with RE

version: F2 version v1.7.2, installed from apt
system: Debian 12 bookworm

files:

00.a.txt
01.b.txt
02.c.txt
03.d.txt
04.e.txt
05.f.txt

cmd:

f2 -f "0(\d\)\." -r "0\$1_"

result:

+----------+--------+--------+
|  INPUT   | OUTPUT | STATUS |
+----------+--------+--------+
| 00.a.txt | 0a.txt | ok     |
| 01.b.txt | 0b.txt | ok     |
| 02.c.txt | 0c.txt | ok     |
| 03.d.txt | 0d.txt | ok     |
| 04.e.txt | 0e.txt | ok     |
| 05.f.txt | 0f.txt | ok     |
+----------+--------+--------+
 INFO  Use the -x or --exec flag to apply the above changes 

expected:

+----------+----------+--------+
|  INPUT   |  OUTPUT  | STATUS |
+----------+----------+--------+
| 00.a.txt | 00_a.txt | ok     |
| 01.b.txt | 01_b.txt | ok     |
| 02.c.txt | 02_c.txt | ok     |
| 03.d.txt | 03_d.txt | ok     |
| 04.e.txt | 04_e.txt | ok     |
| 05.f.txt | 05_f.txt | ok     |
+----------+--------+--------+
 INFO  Use the -x or --exec flag to apply the above changes 

[Feature Request] Add an option that allows passing a list of files as argument

In some cases we need to batch rename some files which don't share any similarities in the file names. It would be a pain in the ass to write a RE to match all of them at the same time. It f2 could take a list of files (directly in the command line or as a list file ) as argument, it would be much easier. Thanks!

[feature request] Is it possible to add DateTimeOriginal time?

I'm a newbie to use F2 and feel it's so fast and cool. I use it to rename my photos.
And is it possible to add DateTimeOriginal time?
It's the time of the shutter actuation (capture time), I think it's meaning ful for a photo rather than file create or change time.

[Question] Custom when fix conflicts

For example currently fixing conflicts mean adding (2), (3), ... to filename

Can I change to _01, _02, ...

Because for some reason I don't want space in filename.

directories to lowercase not working

The command
f2 -D -f '.*.' -r {{tr.lw}}'
does produce a correct preview with all upercase letters changes into lowercases, however,
f2 -verbose -x -D -f '.*.' -r {{tr.lw}}'
produces a lot of success messages like "SUCCESS Renamed Ludwig_Hirsch to ludwig_hirsch" but does not change a thing.

the command "mv Ludwig_Hirsch ludwig_hirsch" works nicely - did i find an issue there or am i doing sth wrong?

Version is 1.8.0 on rasbian buster, Filesystem is vfat - maybe that is the culprit?

[bug] (windows) open System Volume Information: Access is denied.

on windows os, when CWD is a drive root, do sth like f2 -R -d -f x -r y raise error open System Volume Information: Access is denied.
it seems like f2 is trying to access the special dir System Volume Information in every drive root, which is actually hidden and should be skipped / ignored by f2 (since the --hidden, -H option is not given)

fails to run on long paths in windows.

Create this Dir:
C:\My Drive\temploweirdo.com\5.Data Structures and Algorithms\1. Asymptotic Analysis and Insertion Sort, Merge Sort\2.Sorting & Searching why bother with these simple tasks
Say a.

Create this file in a:
1. Sorting & Searching- why bother with these simple tasks- - Data Structure & Algorithms - Part-2.mp4

Now running f2 -f '.*' in a, fails with Path Not Specified Error.

Cause of error:

func isHidden(filename, baseDir string) (bool, error) {
// dotfiles also count as hidden
if filename[0] == dotCharacter {
return true, nil
}
pointer, err := syscall.UTF16PtrFromString(filepath.Join(baseDir, filename))
if err != nil {
return false, err
}
attributes, err := syscall.GetFileAttributes(pointer)
if err != nil {
return false, err
}
return attributes&syscall.FILE_ATTRIBUTE_HIDDEN != 0, nil
}

Specifically, syscall.GetFileAttributes(), most probably because of long path names.


Possible Solutions:
Appending \\?\ in front of an absolute path. (But you seem to use relative path for baseDir)

I'm not sure though, please check once again.
Please make sure that it works with long file names and paths.

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.