![]() |
VOOZH | about |
π Image
π Image
Deutsch π Image
EspaΓ±ol π Image
FranΓ§ais π Image
Italiano π Image
RomΓ’nΔ
It may be hard to sort the files recovered by PhotoRec. You can find here some ideas to help you in this process.
https://github.com/lconte/Copy-PhotoRecFilesbyExtension.ps1
Example: $ python recovery.py /home/me/recovered_files /home/me/sorted_files
#!/usr/bin/env python
import os
import os.path
import shutil
import sys
source = sys.argv[1]
destination = sys.argv[2]
while not os.path.exists(source):
source = raw_input('Enter a valid source directory\n')
while not os.path.exists(destination):
destination = raw_input('Enter a valid destination directory\n')
for root, dirs, files in os.walk(source, topdown=False):
for file in files:
extension = os.path.splitext(file)[1][1:].upper()
destinationPath = os.path.join(destination,extension)
if not os.path.exists(destinationPath):
os.mkdir(destinationPath)
if os.path.exists(os.path.join(destinationPath,file)):
print('WARNING: this file was not copied :' + os.path.join(root,file))
else:
shutil.copy2(os.path.join(root,file), destinationPath)
There are a more extended Python programs like
that do the following things with your recovered data:
Here is an alternative implementation which "copies" much more quickly (by creating "hard links"):
#!/bin/bash
recup_dir="${1%/}"
[ -d "$recup_dir" ] || {
echo "Usage: $0 recup_dir";
echo "Mirror files from recup_dir into recup_dir.by_ext, organized by extension";
exit 1
};
find "$recup_dir" -type f | while read k; do
ext="${k##*.}";
ext_dir="$recup_dir.by_ext/$ext";
[ -d "$ext_dir" ] || mkdir -p "$ext_dir";
echo "${k%/*}"
ln "$k" "$ext_dir";
done
Save it as photorec-sort-by-ext and run
$ bash photorec-sort-by-ext /home/me/recovered_files
This will create a folder called /home/me/recovered_files.by_ext
If you are only interested in files with a specific extension (e.g. only .jpg) you can use the following *nix command to find all files in the recovered directories and copy them to a new location:
$ find /path/to/recovered/directories -name \*.jpg -exec cp {} /path/to/new/folder/ \;
#!/usr/bin/perl -w
# read optional working directory from the command line:
$dir = (@ARGV > 0) ? $ARGV[0] : '.';
$dir =~ s/\/*$//; # truncate trailing '/'s
foreach $file (glob "$dir/*") {
chomp $file;
open(EXIF, '-|', 'jhead', '-v', $file) or die "Not found jhead $!";
if (defined(<EXIF>)) {
foreach $line (<EXIF>) {
if ($line =~ /Canon maker tag 0008 Value = [1-9]\d\d(\d{1,8})$/) {
rename($file, "$dir/IMG_$1.JPG");
print "$dir/IMG_$1.JPG from $file\n";
last;
}
}
close EXIF or die "EXIF: $! $?";
}
}
Additionally restore the files into there original folder tree: --UlfZibis 16:10, 17 January 2018 (CET)
#!/usr/bin/perl -w
# read optional working directory from the command line:
$dir = (@ARGV > 0) ? $ARGV[0] : '.';
$dir =~ s/\/*$//; # truncate trailing '/'s
foreach $file (glob "$dir/*") {
chomp $file;
open(EXIF, '-|', 'jhead', '-v', $file) or die "Not found jhead $!";
if (defined(<EXIF>)) {
$folder_no = '000';
$picture_no = '0000';
$date = '0000';
foreach $line (<EXIF>) {
if ($line =~ /Canon maker tag 0008 Value = ([1-9]\d\d)(\d{1,8})$/) {
$folder_no = $1;
$picture_no = $2;
}
if ($line =~ /Time\s*:\s*\d{4}:(\d\d):(\d\d)\s[\d:]{8}$/) {
$date = "$1$2";
# $date = "$2$1"; # if camera language setting = german
last;
}
}
print "$dir/$folder_no\_$date/IMG_$picture_no.JPG from $file\n";
mkdir("$dir/$folder_no\_$date");
rename($file, "$dir/$folder_no\_$date/IMG_$picture_no.JPG");
close EXIF or die "EXIF: $! $?";
}
}
Or use this script to list all directories, search for files of a certain size, and place them in a date-based directory:
#!/usr/bin/perl -w
$working_dir = '/home/myhome/';
$result_dir = '/home/myhome/photos/'
$jhead_bin = '/usr/bin/jhead';
@rec_dirs = `ls ${working_dir} | grep recup_dir`;
foreach $recup_dir (@rec_dirs) {
print "Scanning ${recup_dir}...";
chomp $recup_dir;
@photos_in_recup = `find ${working_dir}${recup_dir}/*jpg -type f -size +800k`;
foreach $photo_file (@photos_in_recup) {
chomp $photo_file;
#print "IMG $photo_file in $recup_dir\n";
@exif = `$jhead_bin -v $photo_file`;
#print "$jhead_bin -v $photo_file\n";
foreach $line (@exif) {
if ($line =~ /Time\s*:\s*([0-9]{4}):([0-9]{2}):([0-9]{2})\s[0-9:]{8}$/) {
print "IMG $photo_file $1-$2-$3\n";
system("mkdir ${result_dir}$1-$2-$3");
# system("mv $photo_file $result_dir/$1-$2-$3/");
last;
}
}
}
}
exiftool -r '-FileName<IMG_${FileIndex}%c.%e' DIR
It uses FileIndex from EXIF information in file to rename to original filename, the %c is checking for duplicate names and appends other digit to the name. And it works recursively (-r).
$ exiv2 -t rename *.jpg
$ find ./ -exec exiv2 -t rename {} \;
In those cases, in which the number of files is very large, specifying a default action, e.g. always rename duplicates (-F) seems advisable:
$ find ./ -exec exiv2 -F -t rename {} \;
In this example, we check for the first 80k of recup_dir*/*.sib
for file in recup_dir.*/*.sib; do MD5=`dd count=20 bs=4k if="$file" 2> /dev/null|md5sum`; echo "$MD5 $file"; done|sort 1a07198de3486ff2ecab7859612fe7ba - Box Clever.sib 33105f4a7997b2e2681e404b3ac895f2 - Random, Matching - 2 bars.sib 376e0c53e78e56ba6f2858d9680f8c6b - 01aIdentifyCommonInst.sib b0b40a516a1e26660748a0a09cdf3207 - 01ArticulationFlashcards.sib
Each checksum is unique - there are no duplicates.
@echo off SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION SET FILELIST= FOR %%i IN (*) DO ( FOR %%j IN (!FILELIST!) DO ( IF %%~zi EQU %%~zj ( fc /b "%%~i" "%%~j">NUL && echo "%%~i" = "%%~j" ) ) SET FILELIST=!FILELIST! "%%~i" ) ENDLOCAL
#!/bin/sh OUTF='rm-dups.sh' if [ -e $OUTF ]; then echo "File $OUTF already exists." exit 1; fi echo "#!/bin/sh" > $OUTF fdupes -r -f . | sed -r 's/(.+)/rm \"&\"/' >> $OUTF chmod +x $OUTF
Most mp3, mp4 and ogg files have embedded information about Title, Album and Author. To automatically rename the recovered audios and videos using this information, you can use
exiftool -r -ext mp3 "-filename<D:\NewDirPath\${artist;} - ${album;}\${title;}%-c.%e" "D:\recup_dir.1"
π Image
π Image
π Image
LibreOffice is a multiplatform and multilingual office suite and an open-source project. Compatible with all other major office suites, the product is free to download, use, and distribute.