Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

List of files that exclude some files

Posted on 2007-10-06
6
Medium Priority
?
752 Views
Last Modified: 2012-05-05
Hi All,

I wanted to see if there was an easy way to use say the find command in linux to build a list of files that I can process with Imagemagick

Reason is I am periodically searching a folder e.g. /foo/* for jpg files that have not been processed. A processed file will have an accompanying with the same filename but different extension. This file denotes that the jpg was previously processed. I want to then ignore this file the next time I process the folder. So, I would like to be able to:

List all jpg files that do not have an accompanying file. E.g. in a folder, their contains files, a.jpg, b.jpg, c.jpg, d.jpg, d.mod. I would like a list of files in that folder that would exclude the d.jpg file, leaving a.jpg, b.jpg, c.jpg.

Want to be able to process a folder recursively.

Either throw all the files to a list file, to then process through with a loop or possibly execute the command inline with the search. E.g. the command I can run to process and replace the existing jpg file is mogrify quality 50 /path/to/foo.jpg > /path/to/foo.compressed

Any help would be greatly appreciated.
0
Comment
Question by:mpaull
  • 2
  • 2
  • 2
6 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 20028902
perl -le '@mod{map/([^.]+)/,<*.mod>}=(); print for grep!exists $mod{(/([^.]+)/)[0]},<*.jpg>;'
0
 
LVL 85

Expert Comment

by:ozo
ID: 20028956
find .  -name '*.jpg' \! -exec bash -c 'test -f `expr substr "$0" 1 \( length "$0" - 4 \)`.mod' {} \;  -print
0
 
LVL 9

Accepted Solution

by:
ghostdog74 earned 750 total points
ID: 20029124
>>>find .  -name '*.jpg' \! -exec bash -c 'test -f `expr substr "$0" 1 \( length "$0" - 4 \)`.mod' {} \;  -print
It might be overkill to call bash  for each jpg found using exec, especially when there are many jpgs...

@OP, in bash, for one directory. I leave you to find a way for recursive.

for i in *.[jm][op][gd]
do
   prefix=${i%%.*}  
   if [ -f ${prefix}.jpg -a -f ${prefix}.mod ];then           
        continue
   else
        echo "$i" #do your image processing here.
   fi
done

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:mpaull
ID: 20029697
Hi ghostdog74

That works great, got it working recursively. Without understanding a whole lot about how the above works, could you perhaps explain it a little? I wanted to do the same thing with now files that have the .mpeg extension, also placing a .mod file when its processed. I could not get it to work with a .mod extension, made it work with .modv by replacing the first for loop with for i in *.[mm][op][ed][gv]

0
 
LVL 9

Expert Comment

by:ghostdog74
ID: 20029797
hi
i am not very good at explanation, however, perhaps you can try this on your terminal

# i=test.jpg
# echo ${i%%.*}
test

for more details see http://tldp.org/LDP/abs/html/parameter-substitution.html

i am sure you know what a for loop is, so i will skip that.
the if statements checks for existence of a jpg as well as a mod file. If they exists, that means they are already processed, so continue the for loop to read in the next file.

0
 

Author Comment

by:mpaull
ID: 20037490
Thanks ghostdog74. I figured out how your code was working, and made some adjustments. The key part that I got from your code was "if [ -f <filename> -a -f <filename>.mod ]". I did not think to do it this way and I did not know about the -a option. Thanks again.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question