Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have over 200 html files, each containing a png format picture, stored on my harddisk.

How can I extract those pictures into a separate folder easily?

share|improve this question
    
Where are the pictures stored? They can't be embedded in the HTML file, the pictures must be referenced, either to a local png file or in the web. –  mrcktz Nov 3 '12 at 0:37
    
I am sure you mean 'complete webpages', as when you save these in your browser, you gain both a .html file and a _files folder; it is the later that actually contains any images. –  user76204 Nov 3 '12 at 16:51
    
Do you need to keep any of the hierarchy info (that is, names of folders that pictures currently exist in)? Do you care if a solution is command-line or GUI-based? –  belacqua Nov 3 '12 at 20:03

1 Answer 1

When you save a complete webpage in your browser, you will have the html file, for example, Mik.html and its accompanying objects (js and pictures etc) in a file called, for example, Mik_files. Obviously, what you want is in those associated folders and not actually within the html file.

What I do is use the following script, which, in this case, finds all the .png images in the accompanying _files folders saved with the html pages. The images are moved to the directory you choose, although it must exist. The script can be modified as you wish-I have used two positional parameters $1 and $2 so you can choose which directory to target ($1) and where to copy the files that are found ($2). Run chmod u+x it to make it executable. You could add another positional parameter if you don't want it to just find .png files each time.

As an example, if it is not in your ~/bin, you could call it with:

./scriptname.sh $HOME/Downloads $HOME/Documents

The contents of the script:

#!/bin/bash

find "$1" -type f -iname '*.png' -print0 | \
while IFS= read -r -d '' f
do 
    mv -- "$f" "$2"  
done

exit 0 
share|improve this answer
    
that was very helpful, thanks Mik –  user90939 Nov 3 '12 at 23:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.