Contribution - Script to sort testdisk/photorec results

Using PhotoRec to recover lost data
Message
Author
datacorder
Posts: 4
Joined: 12 May 2012, 22:42

Contribution - Script to sort testdisk/photorec results

#1 Postby datacorder » 12 May 2012, 22:45

Hi all,

Those of you using testdisk/photorec free software for recovering lost files shall know what means searching specific file types as images in results.

I just did a short python script that sorts all the files extracted by testdisk/photorec in folders sorted by filetype (images, pdf, video, etc).

You can check it too in my website at http://system-tricks.com/index.php/data ... y-results/

Hope you find it useful.

Code: Select all

#!/usr/bin/env python
#
# System-Tricks - http://system-tricks.com
# Copyleft 2012 - Luis A. Fernandez (datacorder@gmail.com)
#
# This program is free software. You can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os, magic
from shutil import copyfile
#================ CONFIG SECTION ================#
# Source folder with photorec/testdisk results:
testdisk_results = 'SOURCE FOLDER WHERE TESTDISK RESULTS ARE'
#
# Destination folder where you want to store the sorted results:
base_destdir = 'DESTINATION FOLDER WHERE YOU WANT TO STORE SORTED RESULTS'
#
# File types to filter out. You can add every MIME-types you are not interested on:
filter = ['application_octet-stream', 'text_plain']
#============= END OF CONFIG SECTION ============#
types = {}
mime = magic.open(magic.MAGIC_MIME)
mime.load()
for dir in os.listdir(testdisk_results):
    for filename in os.listdir(os.path.join(testdisk_results, dir)):
        file = os.path.join(testdisk_results, dir, filename)
        filetype = mime.file(file).split(';')[0].replace('/', '_').replace(" ", "_").split(',')[0]
        if filetype in filter:
            continue
        if not filetype in types:
            types[filetype] = 1
        else:
            types[filetype] += 1
        print filename + ": " + filetype
        destdir = os.path.join(base_destdir, filetype)
        destfile = os.path.join(destdir, filename)
        if os.path.exists(destdir):
            try:
                copyfile(file, destfile)
            except Exception, e:
                print "Error copying " + filename + ": " + str(e)
                continue
        else:
            os.makedirs(destdir)
            try:
                copyfile(file, destfile)
            except Exception, e:
                print "Error copying " + filename + ": " + str(e)
                continue
print "\n** Results:\n--------------------"
for type in types:
    print type + ": " + str(types[type]) + " files"
print print "\n---------------------------\n\n* Finished. Results stored in " + base_destdir + "\n\n"
Last edited by datacorder on 15 May 2012, 09:54, edited 2 times in total.

Sponsored links

User avatar
remy
Posts: 457
Joined: 25 Mar 2012, 10:21
Location: Strasbourg, France.
Contact:

Re: Contribution - Script to sort testdisk/photorec results

#2 Postby remy » 15 May 2012, 09:23

Did not try yours, but will test later.

By the way, there are already scripts like yours. Solutions are there :

http://www.cgsecurity.org/wiki/After_Using_PhotoRec

EDIT : BTW, could be a good idea to specify your licence for this script. Is it under GPL, copyleft, CCBY... ?
Your webpage is under copyleft, but nothing there tells to user for the script. ;)
J'ai pour habitude d'aller au bout de l'aide que j'apporte. Si vous pensez que je vous ai abandonné, et que je ne l'ai pas fait explicitement, c'est que votre message est enfoui avec d'autres. Relancez-moi (modérément) par mail.

datacorder
Posts: 4
Joined: 12 May 2012, 22:42

Re: Contribution - Script to sort testdisk/photorec results

#3 Postby datacorder » 15 May 2012, 09:53

Ei remy, thank you very much. I forgotten the license. Now it's under GPL, of course.

I didn't knew about that script. Anyway I hope it's useful.

Cheers!

User avatar
remy
Posts: 457
Joined: 25 Mar 2012, 10:21
Location: Strasbourg, France.
Contact:

Re: Contribution - Script to sort testdisk/photorec results

#4 Postby remy » 15 May 2012, 10:19

I'll let you know next time I've a datarecovery to do with many filetypes. I'll try your script also and compare results, and time taken. But as far as I can see (I don't know enough python) the structure is very similar with the one in the wiki page.

BTW, are you involved in DR ?
J'ai pour habitude d'aller au bout de l'aide que j'apporte. Si vous pensez que je vous ai abandonné, et que je ne l'ai pas fait explicitement, c'est que votre message est enfoui avec d'autres. Relancez-moi (modérément) par mail.

datacorder
Posts: 4
Joined: 12 May 2012, 22:42

Re: Contribution - Script to sort testdisk/photorec results

#5 Postby datacorder » 16 May 2012, 12:25

Great, will be great receive your feedback.

I have a small DR business for giving service to some computer repair stores in my area. Just to recovering data from non physical damages, you know. I would like to buy some stuff later in order to expand it but at the moment I'm focused on my main job.

I think on it as one of the best options for my retirement ;)

User avatar
remy
Posts: 457
Joined: 25 Mar 2012, 10:21
Location: Strasbourg, France.
Contact:

Re: Contribution - Script to sort testdisk/photorec results

#6 Postby remy » 17 May 2012, 10:28

Do not hesitate to contact me by PM. I'm in the same situation : I was a teacher (since 12 years) and I decide to change my life and create a Cie in DR. Where are you from ?
J'ai pour habitude d'aller au bout de l'aide que j'apporte. Si vous pensez que je vous ai abandonné, et que je ne l'ai pas fait explicitement, c'est que votre message est enfoui avec d'autres. Relancez-moi (modérément) par mail.

datacorder
Posts: 4
Joined: 12 May 2012, 22:42

Re: Contribution - Script to sort testdisk/photorec results

#7 Postby datacorder » 17 May 2012, 14:35

Greaet, thank you remy, I'm sure that I will contact you forward :)

I'm from Spain. Is you DR bussines working??

User avatar
remy
Posts: 457
Joined: 25 Mar 2012, 10:21
Location: Strasbourg, France.
Contact:

Re: Contribution - Script to sort testdisk/photorec results

#8 Postby remy » 18 May 2012, 14:38

Yes, like a little Cie begining, but... good beginning.
J'ai pour habitude d'aller au bout de l'aide que j'apporte. Si vous pensez que je vous ai abandonné, et que je ne l'ai pas fait explicitement, c'est que votre message est enfoui avec d'autres. Relancez-moi (modérément) par mail.


Return to “File recovery”

Who is online

Users browsing this forum: No registered users and 0 guests