Can't get the files sorted out(python extension won't work)

Using PhotoRec to recover lost data
Forum rules
When asking for technical support:
- Search for posts on the same topic before posting a new question.
- Give clear, specific information in the title of your post.
- Include as many details as you can, MOST POSTS WILL GET ONLY ONE OR TWO ANSWERS.
- Post a follow up with a "Thank you" or "This worked!"
- When you learn something, use that knowledge to HELP ANOTHER USER LATER.
Before posting, please read https://www.cgsecurity.org/testdisk.pdf
Locked
Message
Author
undeadmerc3
Posts: 5
Joined: 17 Apr 2023, 04:00

Can't get the files sorted out(python extension won't work)

#1 Post by undeadmerc3 »

Hi. I have a 64 GB USB thumb drive which recently stopped working. I'm able to "recover" the files, but when I recover the files they aren't sorted out and there are multiple versions of the same file when I open them and I can't tell which of version of each file is the latest. I tried using the python extension, but even after installing python and the Github powershell script it won't work. I get this error message:
Command 'python' not found, did you mean:
command 'python3' from deb python3
command 'python' from deb python-is-python3

I try adding a 3 at the end of python at the start of the command line only to get this message:
python3: can't open file '/home/darkone/recup_dir.1': [Errno 2] No such file or directory

User avatar
cgrenier
Site Admin
Posts: 5432
Joined: 18 Feb 2012, 15:08
Location: Le Perreux Sur Marne, France
Contact:

Re: Can't get the files sorted out(python extension won't work)

#2 Post by cgrenier »

Code: Select all

import os
import os.path
import shutil

destination = '.'
source = '.'
exts = { 'ab', 'aif', 'apple', 'asf', 'avi', 'bmp', 'cr2', 'Desktop', 'doc', 'docx', 'epub', 'gif', 'html', 'icc', 'ico', 'indd', 'jp2', 'jpg', 'lnk', 'mid', 'mkv', 'mov', 'mp3', 'mp4', 'mpg', 'm2ts', 'nef', 'numbers', 'odt', 'orf', 'pdf', 'plist', 'png', 'ppt', 'pptx', 'psd', 'sqlite', 'svg', 'swf', 'tif', 'ttf', 'txt', 'vfb', 'woff', 'xlsx', 'xml', 'xmp', 'wav', 'wma', 'wmv', 'zip', '3gp'}
for ext in exts:
    fn_dir = os.path.join(source, ext)
    try:
      os.mkdir(fn_dir)
    except os.error:
      pass

for fn_dir in os.listdir(source):
    if fn_dir.startswith("recup_dir."):
#        print(fn_dir)
        for file in os.listdir(os.path.join(source, fn_dir)):
            ext = os.path.splitext(file)[1][1:]
            src = os.path.join(source, fn_dir, file)
            if ext in exts:
                dst = os.path.join(source, ext, file)
#                print(src, dst)
                os.rename(src, dst)
            elif file[0] != '.':
                dst = os.path.join(source, 'recup_dir.1', file)
#                print(src, dst)
                os.rename(src, dst)
Can you put this python script in the parent directory of recup_dir.1 and try it ?

undeadmerc3
Posts: 5
Joined: 17 Apr 2023, 04:00

Re: Can't get the files sorted out(python extension won't work)

#3 Post by undeadmerc3 »

Do you mean launching those command lines in the terminal at the recup_dir.1? I'm not used to python so this is a chance for a learning experience for me.

User avatar
cgrenier
Site Admin
Posts: 5432
Joined: 18 Feb 2012, 15:08
Location: Le Perreux Sur Marne, France
Contact:

Re: Can't get the files sorted out(python extension won't work)

#4 Post by cgrenier »

- Copy /paste the lines in a file named sort_by_ext.py
- If the directories where you have recovered your files are /home/darkone/recup_dir.1 recup_dir.2..., save this file in /home/darkone/
- Run python3 sort_by_ext.py

undeadmerc3
Posts: 5
Joined: 17 Apr 2023, 04:00

Re: Can't get the files sorted out(python extension won't work)

#5 Post by undeadmerc3 »

Sorry for the late reply. I'm not used to running python. How do I make a python file?
Update:I managed to make the file, but it's not letting put the python file in. How do I manage to move files into the recup_dir1 folder?

User avatar
cgrenier
Site Admin
Posts: 5432
Joined: 18 Feb 2012, 15:08
Location: Le Perreux Sur Marne, France
Contact:

Re: Can't get the files sorted out(python extension won't work)

#6 Post by cgrenier »

Do not put the script in recup_dir.1 but in its parent directory.

undeadmerc3
Posts: 5
Joined: 17 Apr 2023, 04:00

Re: Can't get the files sorted out(python extension won't work)

#7 Post by undeadmerc3 »

cgrenier wrote: 22 Apr 2023, 12:34 Do not put the script in recup_dir.1 but in its parent directory.
I think i'm almost there. I managed to open the terminal at downloads(ironically where the recup_dir.1 files are. After doing so, the other recup_dir folders are completely empty, but for what ever reason I don't think they are in order with the newest version of each file to the last. I have the folder set to sort the files from last modified to first in the folder options. They still seem randomly placed.
Screenshot from 2023-04-22 22-31-06.png
Screenshot from 2023-04-22 22-31-06.png (27.01 KiB) Viewed 2207 times
Screenshot from 2023-04-22 22-36-51.png
Screenshot from 2023-04-22 22-36-51.png (88.17 KiB) Viewed 2207 times


Sorry if this is dragging out, but I think I am getting somewhere with the other recup folders being emptied into the first one. Sounds like a step in the right direction. Is there something i'm missing?
Screenshot from 2023-04-22 22-30-53.png
Screenshot from 2023-04-22 22-30-53.png (93.99 KiB) Viewed 2207 times

undeadmerc3
Posts: 5
Joined: 17 Apr 2023, 04:00

Re: Can't get the files sorted out(python extension won't work)

#8 Post by undeadmerc3 »

Still here? It's been awhile. Can you send me a link with the file? This is dragging on for too long.

Locked