File Extensions

R

Robin Clay

Greetings !

OK, so my add-on hard drive is a tad screwed up - somehow my "My Pictures"
Folder has been converted into a file.

CHKDSK has been so kind(?) as to "recover" these "lost files", and name them
as FILE0001.CHK, etc. in folders called FOUND.000 etc.

As I understand it, some of those files are plain text files, so I could
simply rename those with the extension .txt

Well, that's not to difficult... ish !

I intend to get VBA to load up the first 64(?) characters of every file, and
compare these with those from the picture files I have back up, I can
eliminate those, leaving to be recovered only those files that I have omitted
to back up.

I have over fifty thousand .CHK file, in seven FOUND folders :(
That number will fit on one Excel WorkSheet.

If VBA checks that the first 64(?) characters are all between CHAR(32) and
CHAR(127), then (if they are), VBA can rename them with the .txt extension.

Now, using the incomparable and essential
-------------------------------------------------
LIST Version 6.4a 9/21/88
(c) Copyright Vernon D. Buerg 1983-88
139 White Oak Circle, Petaluma CA 94952
For personal use only. May not be sold.
-------------------------------------------------
it seems to me that
all .ZIP files seem to start with Hex(504B03) i.e. "PK"
all .PDF files seem to start with Hex(25504446) i.e. "%PDF"
all BitMap files (.BMP) seem to start with "BM"
all .TIF files seem to start with Hex(49492A) i.e. II*


So if SKS could
a) confirm that my logic is sound; and
b) advise me on how many characters I need to test; and
c) provide the information that is contained within
each file that identifies its type,

then I can rename the files with
the correct extensions and look at the contents !

Pretty please?

Or any other ideas - perhaps there is already
software "out there" that I could use ?

Others MUST have had this challenge before !

The Symantec help line couldn't (or wouldn't) advise.



Regards

Robin
 
D

Dave Peterson

Before you do this, you may want to try a few renames manually. Open the file
(in notepad?) and see what the first few characters are.

Then rename that file accordingly.

Then try to open it in the appropriate application.

My bet (from looking at .chk's in the past) is that not many of them will be
opened.

I would put a few of those *.chk files in their own dedicated folder. It'll be
easier to clean up the bad .bmp files if they're segregated from the real .bmp
files.

Then try something like:

Option Explicit
Sub LookAtFiles()

Dim myFileNames As Variant
Dim fCtr As Long

myFileNames = Application.GetOpenFilename _
(FileFilter:="CheckDisk Files, *.chk", _
MultiSelect:=True)

If IsArray(myFileNames) Then
For fCtr = LBound(myFileNames) To UBound(myFileNames)
Call LookAtAndRename(CStr(myFileNames(fCtr)))
Next fCtr
End If

MsgBox "done"

End Sub

Sub LookAtAndRename(myFileName As String)

'all .ZIP files seem to start with Hex(504B03) i.e. "PK"
'all .PDF files seem to start with Hex(25504446) i.e. "%PDF"
'all BitMap files (.BMP) seem to start with "BM"
'all .TIF files seem to start with Hex(49492A) i.e. II*

Dim fNum As Long
Dim Buffer As String * 64
Dim NewFileName As String
Dim myExt As String

NewFileName = Left(myFileName, Len(myFileName) - 4)

fNum = FreeFile
Open myFileName For Binary As #fNum
Buffer = Space(64)
Get fNum, , Buffer
Close fNum

Buffer = LCase(Buffer)

myExt = ""
If Buffer Like "bm*" Then
myExt = "bmp"
ElseIf Buffer Like "pk*" Then
myExt = "zip"
ElseIf Buffer Like "%pdf*" Then
myExt = "pdf"
ElseIf Buffer Like "ii*" Then
myExt = "tif"
End If

If myExt = "" Then
'do nothing
Else
Name myFileName As NewFileName & "." & myExt
End If

End Sub

Run the first procedure and select as many as you want (ctrl-a to grab them all)
or click and ctrl-click to select a few less.

(don't get your hopes up!)
 
R

Robin Clay

iya, Dave !

Long time no....

Thank you for responding,
and offering your wisdom once more!

I have saved your message
and shall give it a go tomorrow.

I have actually tried renaming
with .BMP a file that seemed
as though it was one such, but
when I double clicked on it, the
process hung, and I had to use
Taskmanager to kill it.


Regards

Robin
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top