Author Topic: Finding files in folder  (Read 1293 times)

woollypigs

  • Mr Peli
    • woollypigs
Finding files in folder
« on: 03 October, 2018, 04:37:58 pm »
Hey

I used one gallery program and all the images there, are 800px wide. I would like to update that to at least 1600/1920px since I'm using another gallery program.

So, all the original photos are living in folder X and the gallery images live in folder Y. But gallery folder isn't all the photos.

Is there a way in win10 or Debian to look in the original folder and only pick/copy the images that is in the gallery folder?

Good news is that files in both folders got the same file name, so that should help in doing so, but I'm blank on where to start.
Current mood: AARRRGGGGHHHHH !!! #bollockstobrexit

Re: Finding files in folder
« Reply #1 on: 03 October, 2018, 04:42:42 pm »
On Debian using the command line you should use the  find  utility.
I can help formulate your find command but probably need to know more specifics.

To find only  JPEG files

find /path/to/gallery   -name "*.jpg"

With find you can optionally specify a command to be run on the file which is found, for example a move or a copy.
find /path/to/gallery -name "*.jpg" -exec ls {} \;

The {} stands for the file which is found. The \; is necessary

Also  rsync  is a hugely useful Swiss Army Knife style utility.

woollypigs

  • Mr Peli
    • woollypigs
Re: Finding files in folder
« Reply #2 on: 03 October, 2018, 04:45:56 pm »
Thanks, but what specifics do you need :)

They are all named in this style "2012-01-07--12.46.13_P1000015.jpg"
I can easy move/copy the folder/files to make it easy regarding path.

Any other details would you need?
Current mood: AARRRGGGGHHHHH !!! #bollockstobrexit

Re: Finding files in folder
« Reply #3 on: 03 October, 2018, 04:46:56 pm »
Original post updated

Re: Finding files in folder
« Reply #4 on: 03 October, 2018, 04:50:46 pm »
https://freefilesync.org/ will probably help do what you want

Re: Finding files in folder
« Reply #5 on: 03 October, 2018, 04:58:03 pm »
Aha! I read your original post. You want to look in the original folder and ONLY select files which have files named similarly in the gallery folder


I would look at piping the output of the find to something which does a Bash file test.

However this is suddenly looking like a small Bash script which loops through all the files in the original folder and runs a file test to see if there is one in the gallery.

Give me ten minutes.

fuaran

  • rothair gasta
Re: Finding files in folder
« Reply #6 on: 03 October, 2018, 05:01:44 pm »
Or go to the gallery folder, and use ls to get a list of all of the files, and pipe that to a text file. Then use that as input for the cp command

woollypigs

  • Mr Peli
    • woollypigs
Re: Finding files in folder
« Reply #7 on: 03 October, 2018, 05:34:54 pm »
Thanks all!

rsync did the job (why didn't I think about that before) :

sudo rsync -avz --update --existing  "source_folder" "destination_folder"
Current mood: AARRRGGGGHHHHH !!! #bollockstobrexit

Re: Finding files in folder
« Reply #8 on: 03 October, 2018, 05:37:42 pm »
My solution as a bash script.  Yeah I know - backticks.  I can use a punch card machine too - really can.

!/bin/bash


# define the directory which contains the gallery thumbnails
export GALLERY=$HOME/gallery
# define the directory which contains the original photo files
export ORIGINALS=$HOME/originals


# loop through all the files in the gallery directory
# we can refine this to select only jpeg files etc
for file in $GALLERY/*
do
    # the baseline utility strips off the directory path
    # Yeah I know - backticks. I am stuck in the 1970s
    original_file=${ORIGINALS}/`basename $file`

    # We now have the name of the original photo file
    # We can do things to this file
    echo $original_file
done