Python and lost files

Discussion in 'Python' started by Timothy W. Grove, Oct 1, 2009.

  1. Recently I purchased some software to recover some files which I had
    lost. (A python project, incidentally! Yes, I should have kept better
    backups!) They were nowhere to found in the file system, nor in the
    recycle bin, but this software was able to locate them and restore them.
    I was just wondering if there was a way using python to view and recover
    files from the hard drive which would otherwise remain lost forever?

    Best regards,
    Tim
    Timothy W. Grove, Oct 1, 2009
    #1
    1. Advertising

  2. Timothy W. Grove

    lallous Guest

    Hello Timothy,

    "Timothy W. Grove" <> wrote in message
    news:...
    > Recently I purchased some software to recover some files which I had lost.
    > (A python project, incidentally! Yes, I should have kept better backups!)
    > They were nowhere to found in the file system, nor in the recycle bin, but
    > this software was able to locate them and restore them. I was just
    > wondering if there was a way using python to view and recover files from
    > the hard drive which would otherwise remain lost forever?
    >


    To recover lost or deleted files you need a specialized tools (such as data
    recovery programs).
    I don't see a way to recover files using python itself but perhaps using a
    data recovery program written in Python.

    --
    Elias
    lallous, Oct 1, 2009
    #2
    1. Advertising

  3. Timothy W. Grove

    alex23 Guest

    "Timothy W. Grove" <> wrote:
    > I was just wondering if there was a way using python to view and recover
    > files from the hard drive which would otherwise remain lost forever?


    I'm not familiar with any Python-based tools for data recovery, but
    you might be interested in mercurial[1], which _is_ (primarily)
    written in Python ;)

    1: http://mercurial.selenic.com/
    alex23, Oct 1, 2009
    #3
  4. Timothy W. Grove

    Carl Banks Guest

    On Sep 30, 11:35 pm, "Timothy W. Grove" <> wrote:
    > Recently I purchased some software to recover some files which I had
    > lost. (A python project, incidentally! Yes, I should have kept better
    > backups!) They were nowhere to found in the file system, nor in the
    > recycle bin, but this software was able to locate them and restore them.


    I could have used that yesterday, if it were able to work for a
    network Samba drive. (Yeah, not likely.)


    > I was just wondering if there was a way using python to view and recover
    > files from the hard drive which would otherwise remain lost forever?


    Obviously, if that program was able to do it, it's possible.

    On Unix-like OSes, and probably others, it's possible to read the raw
    data on a disk the same way as you would read any file. So Python can
    do it without any system-level programming. Recent versions (I think
    2.6+) can use mmap, too, now that it supports an offset parameter.

    I don't think you can do that in Windows, though. I think you'd have
    to use special system calls (via ctypes, for example).


    Carl Banks
    Carl Banks, Oct 1, 2009
    #4
  5. On 2009-10-01, Timothy W. Grove <> wrote:

    > Recently I purchased some software to recover some files which
    > I had lost. (A python project, incidentally! Yes, I should
    > have kept better backups!) They were nowhere to found in the
    > file system, nor in the recycle bin, but this software was
    > able to locate them and restore them. I was just wondering if
    > there was a way using python to view and recover files from
    > the hard drive which would otherwise remain lost forever?


    Yes, you could write a filesystem analysis and file recovery
    program in Python. [I guess that's what you were asking.]

    --
    Grant
    Grant Edwards, Oct 2, 2009
    #5
  6. Timothy W. Grove

    Dave Angel Guest

    Carl Banks wrote:
    > On Sep 30, 11:35 pm, "Timothy W. Grove" <> wrote:
    >
    >> Recently I purchased some software to recover some files which I had
    >> lost. (A python project, incidentally! Yes, I should have kept better
    >> backups!) They were nowhere to found in the file system, nor in the
    >> recycle bin, but this software was able to locate them and restore them.
    >>

    >
    > I could have used that yesterday, if it were able to work for a
    > network Samba drive. (Yeah, not likely.)
    >
    >
    >
    >> I was just wondering if there was a way using python to view and recover
    >> files from the hard drive which would otherwise remain lost forever?
    >>

    >
    > Obviously, if that program was able to do it, it's possible.
    >
    > On Unix-like OSes, and probably others, it's possible to read the raw
    > data on a disk the same way as you would read any file. So Python can
    > do it without any system-level programming. Recent versions (I think
    > 2.6+) can use mmap, too, now that it supports an offset parameter.
    >
    > I don't think you can do that in Windows, though. I think you'd have
    > to use special system calls (via ctypes, for example).
    >
    >
    > Carl Banks
    >
    >

    To write such a program, you have two challenges. First is to get
    read-access to the raw sectors of the partition, and second, to analyze
    them to discover which ones are interesting, and how they need to be
    combined to reconstruct the lost data.

    In Windows, the first challenge is pretty easy for drives other than the
    system drive (usually drive C:, but not necessarily.) You use one of
    the following:
    \\.\X: where X: is the logical drive letter
    or \\.\PhysicalDriveN where N is the hard drive # (0, 1, 2...)
    Normally you'd use this only if the data is on a "deleted" or "foreign"
    partition that Windows doesn't recognize.

    Naturally, make sure the scratch files and result files you create are
    going to a different partition/drive.

    The second challenge is the file system format. If you go with physical
    drive, you'll have to parse the partitioning information to find
    individual partitions within the drive, and once you get to a partition,
    you have to parse the particular file system. Most likely NTFS (which
    has had several versions). But could be FAT32, FAT16, or a couple of
    other less likely candidates.

    While you can also do this for a system partition, there are some
    challenges that I've no relevant experience with.

    DaveA
    Dave Angel, Oct 2, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ron Clarke

    Sound lost when playing AVI files

    Ron Clarke, Feb 24, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    349
    Ron Clarke
    Feb 24, 2004
  2. Replies:
    0
    Views:
    315
  3. Simon Gare
    Replies:
    0
    Views:
    385
    Simon Gare
    Jul 30, 2006
  4. Simon Gare
    Replies:
    0
    Views:
    325
    Simon Gare
    Aug 2, 2006
  5. Michel Claveau - MVP

    Python 2.7 and cmd on Windows 7 64 (files lost)

    Michel Claveau - MVP, Jun 23, 2011, in forum: Python
    Replies:
    6
    Views:
    1,584
    Martin v. Loewis
    Jun 24, 2011
Loading...

Share This Page