ayoisaiah / f2

F2 is a cross-platform command-line tool for batch renaming files and directories quickly and safely. Written in Go!
https://f2.freshman.tech
MIT License
866 stars 38 forks source link

Moving files to another directory outside starting path #55

Closed joeldebruijn closed 5 months ago

joeldebruijn commented 1 year ago

Besides renaming files I'm experimenting with using F2 to move files to other folders (and migrate from Robobasket for Windows in the process).

The use case is a folder with a Camera roll and storing them somewhere else in ' daily folders' . The files are like this YYYYMMDD_hhmm,jpg

Example:

I tried this:

  1. f2 -f '(\d{8})_(\d{6}).(jpg|mp4)' -r "/$home/S/Joel/Media/Fotos/$1/{f}{ext}" assuming I could use $home as a variable.
  2. f2 -f '(\d{8})_(\d{6}).(jpg|mp4)' -r "/home/S/Joel/Media/Fotos/$1/{f}{ext}" assuming I could use /home as an absolute path.

Both times it creates a directorystructure /home/S/Joel/Media/Fotos/.../ WITHIN my cameraroll folder.

Is moving outside the current path possible or am I missing something?

ayoisaiah commented 1 year ago

Hi @joeldebruijn,

It's currently not possible but, this sounds like something that should be supported for sure and it should be straightforward enough to implement.

joeldebruijn commented 1 year ago

Thanks! For now I just sort within the starting path and move the resulting directories by hand once a week or so.

Maybe it needs some kind of flag to choose between relative and absolute paths?

ayoisaiah commented 1 year ago

@joeldebruijn Yes essentially a flag to specify a different root directory will do trick, but will explore other options too 🙂

joeldebruijn commented 8 months ago

I just read https://github.com/ayoisaiah/f2/wiki/F2-tutorial#integration-with-other-programs and ' piping' and make combinations with other programs. Could something like this work? Replace example is random. To move every matched file with its new filename in a new place?

f2 -f '{f}.{ext}' -r '{%03d}{ext}' | mv {%03d}{ext} $HOME/Test

ayoisaiah commented 8 months ago

What I could do is provide a flag that can help you execute a command on each renamed file. For example:

f2 -f '{f}.{ext}' -r '{%03d}{ext}' --cmd mv {} $HOME/Test

Where {} is the file path that was renamed.

I will also add the ability to use F2's output as an input to other programs. For now, you can only use the output of other programs as input to F2

ayoisaiah commented 5 months ago

@joeldebruijn You can do something like this now (see latest nightly release):

f2 -f 'master' -r 'main' -x --non-interactive | xargs -I {} mv {} dist/

The --non-interactive flag instructs F2 to print the renamed paths so that it can be used as input for a different program.

joeldebruijn commented 5 months ago

Will try and test! Thnx!

ayoisaiah commented 2 weeks ago

@joeldebruijn I needed this feature recently so I've now added a new --target-dir flag that allows you to specify a path to a directory that the files should be moved to. The path will be created if it doesn't exist already:

f2 -r '{x.cdt.YYYY}/{x.cdt.MM}-{x.cdt.MMM}/{x.cdt.YYYY}-{x.cdt.MM}-{x.cdt.DD}/{f}{ext}' -R --target-dir ~/Pictures/
*———————————————————————————————————*————————————————————————————————————————————————————————*————————*
|             ORIGINAL              |                        RENAMED                         | STATUS |
*———————————————————————————————————*————————————————————————————————————————————————————————*————————*
| DSC04798.ARW                      | /home/ayo/Pictures/2024/06-Jun/2024-06-29/DSC04798.ARW | ok     |
| DSC04798.JPG                      | /home/ayo/Pictures/2024/06-Jun/2024-06-29/DSC04798.JPG | ok     |
| DSC04801.ARW                      | /home/ayo/Pictures/2024/06-Jun/2024-06-29/DSC04801.ARW | ok     |
| DSC04801.JPG                      | /home/ayo/Pictures/2024/06-Jun/2024-06-29/DSC04801.JPG | ok     |
| _DSC1771.JPG                      | /home/ayo/Pictures/2024/06-Jun/2024-06-27/_DSC1771.JPG | ok     |
| birthday-2024/_DSC0430.ARW        | /home/ayo/Pictures/2024/06-Jun/2024-06-28/_DSC0430.ARW | ok     |
| birthday-2024/_DSC0430.JPG        | /home/ayo/Pictures/2024/06-Jun/2024-06-28/_DSC0430.JPG | ok     |
| birthday-2024/_DSC0433.ARW        | /home/ayo/Pictures/2024/06-Jun/2024-06-28/_DSC0433.ARW | ok     |
| birthday-2024/_DSC0433.JPG        | /home/ayo/Pictures/2024/06-Jun/2024-06-28/_DSC0433.JPG | ok     |
| family trip - berlin/_DSC1767.ARW | /home/ayo/Pictures/2024/06-Jun/2024-06-27/_DSC1767.ARW | ok     |
| family trip - london/_DSC0092.JPG | /home/ayo/Pictures/2024/05-May/2024-05-30/_DSC0092.JPG | ok     |
| family trip - london/_DSC0093.ARW | /home/ayo/Pictures/2024/05-May/2024-05-30/_DSC0093.ARW | ok     |
| family trip - london/_DSC0093.JPG | /home/ayo/Pictures/2024/05-May/2024-05-30/_DSC0093.JPG | ok     |
| my-wedding/DSC05194.ARW           | /home/ayo/Pictures/2024/07-Jul/2024-07-02/DSC05194.ARW | ok     |
| my-wedding/DSC05194.JPG           | /home/ayo/Pictures/2024/07-Jul/2024-07-02/DSC05194.JPG | ok     |
*———————————————————————————————————*————————————————————————————————————————————————————————*————————*

In your original query, you would have done this:

f2 -f '(\d{8})_(\d{6}).(jpg|mp4)' -r "$1/{f}{ext}"  --target-dir ~/Joel/Media/Fotos/
candrapersada commented 1 week ago

how to remove old subdirectories aftars moved? --recursive

ayoisaiah commented 1 week ago

@candrapersada I added a --clean flag. Please download the latest nightly to try it out

ayoisaiah commented 1 week ago

@candrapersada That's what the --target-dir flag described above does.

candrapersada commented 1 week ago

what i mean is there any option to merge files from subdirectories into one folder without moving to new location and still in the same location in terminal