Page 1 of 1
Can't get the files sorted out(python extension won't work)
Posted: 17 Apr 2023, 04:09
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
Re: Can't get the files sorted out(python extension won't work)
Posted: 17 Apr 2023, 08:15
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 ?
Re: Can't get the files sorted out(python extension won't work)
Posted: 18 Apr 2023, 00:45
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.
Re: Can't get the files sorted out(python extension won't work)
Posted: 19 Apr 2023, 06:39
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
Re: Can't get the files sorted out(python extension won't work)
Posted: 22 Apr 2023, 03:44
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?
Re: Can't get the files sorted out(python extension won't work)
Posted: 22 Apr 2023, 12:34
by cgrenier
Do not put the script in recup_dir.1 but in its parent directory.
Re: Can't get the files sorted out(python extension won't work)
Posted: 23 Apr 2023, 03:41
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 (27.01 KiB) Viewed 6420 times

- Screenshot from 2023-04-22 22-36-51.png (88.17 KiB) Viewed 6420 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 (93.99 KiB) Viewed 6420 times
Re: Can't get the files sorted out(python extension won't work)
Posted: 04 May 2023, 03:52
by undeadmerc3
Still here? It's been awhile. Can you send me a link with the file? This is dragging on for too long.