You are not logged in.

#1 2005-08-28 16:28:58

MartinZ
Member
From: Chiloé, Chile
Registered: 2005-06-10
Posts: 379

file extensions lost

I didn't know where to ask this, sorry if out of topic.

Sometime ago, under windows, lots of my personal files got with wrong extension (o no extension at all) at a partition task (that's why i dont use Partition Tragic anymore).

How can i fix them? I looked for "file" and it recognizes almost every extension well, but don't know how to correct them.

Thanks in advance.


All your base are belong to us

Offline

#2 2005-08-28 17:08:55

Kern
Member
From: UK
Registered: 2005-02-09
Posts: 464

Re: file extensions lost

there are some "batch renaming" scripts out and about.
Whether they would work or not would depend on a few more details.

how many file types, and are they in subdirectories, are there mixed extensions in many directories etc.

Any more info would be useful.

Offline

#3 2005-08-29 22:15:36

MartinZ
Member
From: Chiloé, Chile
Registered: 2005-06-10
Posts: 379

Re: file extensions lost

There's no much i can tell...

I was converting a partition from NTFS to FAT32 (never try that!!!!) and about 10% of filenames from a whole, big (about 8 GB) directory changed to weird ones and lost their extensions. Unfortunelly, i need that info accesible from windoze (not mine, but from my sister). This directory has lots of filetypes and subdirectories. I already tried windows-based aplications, but none of them worked at all. They all recognized (more or less) filetypes, but couldn't rename them.

I think windows is a crap, but that's just my personal opinion.


All your base are belong to us

Offline

#4 2005-08-29 23:18:22

bosewicht
Member
From: Honolulu, HI
Registered: 2004-05-29
Posts: 67

Re: file extensions lost

did they all change in a uniform way?
All .exe's in dir A have been changed to .pxe's? or are they just random?


<b>There are 10 kinds of people in the world - those who understand binary
and those who don't.</b>

<b>I'm Steve and I'm a Super Villian</b>
http://www.rofl.name/flash/switchlinux4

Offline

#5 2005-08-30 03:38:07

MartinZ
Member
From: Chiloé, Chile
Registered: 2005-06-10
Posts: 379

Re: file extensions lost

No, random changes (i mean, i didn't find a pattern).
They all took a new shorter filename, most of them 7 letters long, and the majority without a single extension, but some kept 1 or 2 characters from the original extension.

Thanks again, hope you can help me


All your base are belong to us

Offline

#6 2005-08-30 08:37:09

Kern
Member
From: UK
Registered: 2005-02-09
Posts: 464

Re: file extensions lost

The only reasoned thought i can come up with is to find something common between certain filetypes / folders so they can be altered in a uniform way.
but even with the 'file' command, it doesnt generate the extension, only a file description.

tried looking for some solutions in the form of file extension correction scripts / programs but had no luck. sorry.

maybe try look at this from a different angle.

Do you "need" the correct extension. perhaps just leave them as they are, and if you need to work in or on one, then open it with the associated application.  then save it as the proper filename.ext

for instance, if i change the extension on any graphics file, gqview still sees it as a graphics file and shows the picture.
if you have My_resume.jkl and know its a .doc document, try open it in openoffice/MSoffice by default.

sorry i cant be of more help.
looks a tough cookie. good luck

Offline

#7 2005-08-30 17:40:30

Snowman
Developer/Forum Fellow
From: Montreal, Canada
Registered: 2004-08-20
Posts: 5,212

Re: file extensions lost

I've made a little script that might help you.  It use file to find the filetype and rename the file.
Usage: 
string is the part of the info returned when you do file <filename>. It should be specific to one filetype only. I did

$ file adjoint-4-7-05.pdf
adjoint-4-7-05.pdf: PDF document, version 1.5

so I use "PDF document" to search for pdf files.
ext is the extension you want to give to the file.

#!/bin/bash

string="PDF document"
ext="pdf"
string2="MP3 file"
ext2="mp3"

for i in $@ ;do

   if file $i |grep -q -F "$string" ; then
      mv $i ${i%.*}.$ext
   fi

   if file $i |grep -q -F "$string2" ; then
      mv $i ${i%.*}.$ext2
   fi

done

you'll need to run it in each directory:
$ ~/script *

The above script will only rename pdf and mp3 files. You might want to  extend it (as I did for mp3) so it renames your principal filetypes.

Good luck.

Offline

#8 2005-08-30 22:18:18

MartinZ
Member
From: Chiloé, Chile
Registered: 2005-06-10
Posts: 379

Re: file extensions lost

Lots of thank, i'll be working on it and tell you


All your base are belong to us

Offline

Board footer

Powered by FluxBB