/*----------------------------------------------------------------------------------------------------------- ;$VER: ExtensionAdd v1.0 by DoMiNaToR (08/01/95) -----------------------------------------------------------------------------------------------------------*/ Call AddLib('rexxsupport.library',0,-30,0) /* Rename/Exists commands are required */ Options Results /* Let DOpus know that results will be needed */ StartAgain: /* If there 20+ selected, we will need loop around */ Status 3 /* Get the selected Window on DOpus */ Window=Result /* and store it in 'Window' variable */ Status 9 Window /* Get the amount of selected entries in the Window */ Entries=Result /* and store it in 'Entries' variable */ Status 13 Window /* Get the name of the directory shown in the Window */ Path=Result /* and store it in 'Path' variable */ Busy On /* Let the user know that the script is running */ If Entries = 0 then /* Check if there are NO entries left to do */ Do /* No, there isn't so... */ ReScan /* Rescan the directory so the changes can be seen */ Toptext 'Operation complete' /* Let the user know that we are done */ Busy Off /* Allow the user to take control again */ Exit /* Exit this program. Bye... */ End If Entries > 20 then /* Check if there is over 20 entries selected */ Do /* Yes, there is so... */ Entries = 20 /* Only do the first 20 */ End Do Loop = 1 to Entries /* Perform action on ALL selected entries (If possible) */ GetNextSelected /* Get the next selected entry */ Name = Result /* and store it in 'Name' variable */ ScrollToShow Name /* Scroll the directory listing down with the operation */ Ensure = StateF(Path||Name) /* Before we go ahead, we'd better check that */ If Left(Ensure,3) = 'FIL' then /* a file is selected and NOT a directory!!! */ Do Call FindFileType /* Go to the routine that detects the type of file */ Call AddExtension /* Go to the routine that tries to add an extension */ End SelectFile '"'Name'"' 0 1 /* Entry is now finished with, so unselect it */ End /* Loop around until ALL entries are dealt with */ Call StartAgain /* Loop back to the start in case there is more entries */ /*---------------------------------------------------------------------------------------------------------*/ FindFileType: /* Sub-Routine: Determine what extension to give the file */ Extension = '' /* Clear the new-extension variable */ Success = Open('fp',Path||Name,'r') /* Open the selected file for examining... */ /* FileType: Graphics Interchange Format - Image Extension: GIF Determine: The first three bytes are characters of G, I and F */ FilePos = Seek('fp',0,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',3) /* Read in appropriate information at that place */ If Info = 'GIF' then Do Extension = 'GIF' Waste = Close('fp') Return End /* FileType: Interchange File Format, InterLeaved BitMap - Image Extension: ILBM Determine: Starting from the 9th byte in the file are the four characters of I, L, B and M */ FilePos = Seek('fp',8,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',4) /* Read in appropriate information at that place */ If Info = 'ILBM' then Do Extension = 'ILBM' Waste = Close('fp') Return End /* FileType: Joint Photographic Expert Group - Image Extension: JPG Determine: Starting from the 7th byte in the file are the four characters of J, F, I and F */ FilePos = Seek('fp',6,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',4) /* Read in appropriate information at that place */ If Info = 'JFIF' then Do Extension = 'JPG' Waste = Close('fp') Return End /* FileType: Tagged Interchange File Format - Image Extension: TIF Determine: The first 8 bytes SEEM to always be $4D4D002A00000008 */ FilePos = Seek('fp',0,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',8) /* Read in appropriate information at that place */ If Info = '4D4D002A00000008'x then Do Extension = 'TIF' Waste = Close('fp') Return End /* FileType: Interchange File Format 8-Octave Sampled Voice (I think) - Sound sample Extension: 8SVX Determine: Starting from the 9th byte in the file are the four characters of 8, S, V and X (as with every IFF file - isn't IFF great ?) */ FilePos = Seek('fp',8,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',4) /* Read in appropriate information at that place */ If Info = '8SVX' then Do Extension = '8SVX' Waste = Close('fp') Return End /* FileType: AmigaGuideŽ Database - Form of Document Extension: guide Determine: The first 9 bytes are '@', 'D', 'A', 'T', 'A', 'B', 'A', 'S' and 'E' */ FilePos = Seek('fp',0,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',9) /* Read in appropriate information at that place */ If Upper(Info) = '@DATABASE' then Do Extension = 'guide' Waste = Close('fp') Return End /* FileType: Workbench Icon Information - Icon Extension: info Determine: The first 8 bytes SEEM to be $E310000100000000 */ FilePos = Seek('fp',0,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',8) /* Read in appropriate information at that place */ If Info = 'E310000100000000'x then Do Extension = 'info' Waste = Close('fp') Return End /* FileType: LHA (I haven't no idea what or if it stands for anything) archive - Archive Extension: LHA Determine: Starting from the 3rd byte in the file are the characters '-', 'l' and 'h' */ FilePos = Seek('fp',2,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',3) /* Read in appropriate information at that place */ If Info = '-lh' then Do Extension = 'LHA' Waste = Close('fp') Return End /* FileType: Dish Masher archive - Archive Extension: DMS Determine: The first 3 bytes are 'D', 'M' and 'S' */ FilePos = Seek('fp',0,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',3) /* Read in appropriate information at that place */ If Info = 'DMS' then Do Extension = 'DMS' Waste = Close('fp') Return End /* FileType: Computer Graphic Metafile Format - Scalable Image Extension: CGM Determine: Starting from the 33st byte in the file are the characters 'C', 'G' and 'M' WARNING!: I had no images to test this on - it is just based on a friends advice.... */ FilePos = Seek('fp',32,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',3) /* Read in appropriate information at that place */ If Info = 'CGM' then Do Extension = 'CGM' Waste = Close('fp') Return End /* FileType: Professional Draw CLIP - Scalable Image Extension: CLIP Determine: The first 4 bytes are the characters 'P', 'D', 'P' and 'F' */ FilePos = Seek('fp',0,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',4) /* Read in appropriate information at that place */ If Info = 'PDPF' then Do Extension = 'CLIP' Waste = Close('fp') Return End /* FileType: Interchange File Format 2D Drawing (I think ?!) - Scalable Image Extension: DR2D Determine: Starting from the 9th byte in the file are the characters 'D', 'R', '2' and 'D' */ FilePos = Seek('fp',8,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',4) /* Read in appropriate information at that place */ If Info = 'DR2D' then Do Extension = 'DR2D' Waste = Close('fp') Return End /* FileType: Adobe Illustrator - Scalable Image Extension: AI Determine: The first 11 bytes read the characters of '%!PS-Adobe-' */ FilePos = Seek('fp',0,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',11) /* Read in appropriate information at that place */ If Info = '%!PS-Adobe-' then Do Extension = 'AI' Waste = Close('fp') Return End /* FileType: Encapsulated Postscript - Scalable Image Extension: EPS Determine: Starting from the 31th byte are the characters reading '!%PS-Adobe-' */ FilePos = Seek('fp',30,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',11) /* Read in appropriate information at that place */ If Info = '%!PS-Adobe-' then Do Extension = 'EPS' Waste = Close('fp') Return End /* FileType: Postscript Adobe Type1 Font Metrics - Scalable Font Extension: AFM Determine: The first 16 bytes read the characters of 'StartFontMetrics' */ FilePos = Seek('fp',0,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',16) /* Read in appropriate information at that place */ If Info = 'StartFontMetrics' then Do Extension = 'AFM' Waste = Close('fp') Return End /* FileType: Postscript Adobe Type1 Font Binary - Scalable Font Extension: PFB Determine: Starting from the 7th byte in the file are the characters reading '%!PS-AdobeFont' */ FilePos = Seek('fp',6,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',14) /* Read in appropriate information at that place */ If Info = '%!PS-AdobeFont' then Do Extension = 'PFB' Waste = Close('fp') Return End /* FileType: PageStream 2.2 - Document Extension: PS Determine: The first 8 bytes SEEM to be $07 23 19 92 00 0D 02 00 */ FilePos = Seek('fp',0,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',8) /* Read in appropriate information at that place */ If Info = '07231992000D0200'x then Do Extension = 'PS' Waste = Close('fp') Return End /* FileType: Interchange File Format Wordworth - Document Extension: WW Determine: Starting from the 9th byte in the file are the characters 'W', 'O', 'W' and 'O' */ FilePos = Seek('fp',8,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',4) /* Read in appropriate information at that place */ If Info = 'WOWO' then Do Extension = 'WW' Waste = Close('fp') Return End /* FileType: Protext - Document Extension: PT Determine: Starting from the 3rd byte in the file are the characters 'P', 'R', 'O' and 'T' */ FilePos = Seek('fp',2,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',4) /* Read in appropriate information at that place */ If Info = 'PROT' then Do Extension = 'PT' Waste = Close('fp') Return End /* FileType: Interchange File Format Animation - Animation Extension: ANIM Determine: Starting from the 9th byte in the file are the characters 'A', 'N', 'I' and 'M' */ FilePos = Seek('fp',8,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',4) /* Read in appropriate information at that place */ If Info = 'ANIM' then Do Extension = 'ANIM' Waste = Close('fp') Return End /* FileType: MED Module - Music Module Extension: MED Determine: The first three bytes of the file read out the characters 'M', 'M' and 'D' */ FilePos = Seek('fp',0,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',3) /* Read in appropriate information at that place */ If Info = 'MMD' then Do Extension = 'MED' Waste = Close('fp') Return End /* FileType: Tracker Module (1) - Music Module Extension: MOD Determine: Starting from the 1080 (!) byte are the bytes (hex) of 4D, 2E, 4B and 2E */ FilePos = Seek('fp',1080,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',4) /* Read in appropriate information at that place */ If Info = '4D2E4B2E'x then Do Extension = 'MOD' Waste = Close('fp') Return End /* FileType: Tracker Module (2) - Music Module Extension: MOD Determine: Starting from the 1080 (!) byte are the bytes (hex) of 46, 4C, 54 and 34 */ FilePos = Seek('fp',1080,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',4) /* Read in appropriate information at that place */ If Info = '464C5434'x then Do Extension = 'MOD' Waste = Close('fp') Return End /* FileType: Powerpacker - Crunched Data File Extension: pp Determine: The first two bytes of the file read out the characters 'P' and 'P' */ FilePos = Seek('fp',0,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',2) /* Read in appropriate information at that place */ If Info = 'PP' then Do Extension = 'pp' Waste = Close('fp') Return End /* FileType: ARexx program - Source code Extension: REXX Determine: The first two bytes of the file are always '/' and '*' */ FilePos = Seek('fp',0,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',2) /* Read in appropriate information at that place */ If Info = '/*' then Do Extension = 'REXX' Waste = Close('fp') Return End /* FileType: AMOS program - Source code Extension: AMOS Determine: The first four characters of the file are always 'A', 'M', 'O' and 'S' */ FilePos = Seek('fp',0,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',4) /* Read in appropriate information at that place */ If Info = 'AMOS' then Do Extension = 'AMOS' Waste = Close('fp') Return End /* FileType: Interchange File Format CMUS (Dunno what it stands for ?!) - Musical Score Extension: CMUS Determine: Starting from the 9th byte in the file are the characters 'C', 'M', 'U' and 'S' */ FilePos = Seek('fp',8,'b') /* Move to appropriate place in file */ Info = ReadCh('fp',4) /* Read in appropriate information at that place */ If Info = 'CMUS' then Do Extension = 'CMUS' Waste = Close('fp') Return End Return /*---------------------------------------------------------------------------------------------------------*/ AddExtension: /* Sub-Routine: Attempt to add the extension (if any) */ If Extension = '' then /* If no extension has been created.... */ Do Toptext '"'Name'" is an unknown filetype' /* Let the user know that the filetype */ Return /* is unknown and move onto the next entry */ End CharPosition = LastPos('.',Name) /* Check if the filename already has an extension... */ NoExt = '' /* Reset the 'NoExt' variable (Filename with no ext) */ If CharPosition > 0 then /* Yes it has, so... */ Do NoExt = DelStr(Name,CharPosition) /* Strip anything after and including the '.' */ If Name = NoExt'.'Extension then /* Is the extension already correct ? */ Do Toptext '"'Name'" already has the correct extension' Return /* Yes, it is - Let the user know and move onto the next.. */ End End If NoExt = '' then /* Is the 'NoExt' variable been changed from nothing ? */ Do NoExt = Name /* No, it hasn't - make it the same as the proper name */ End Ensure = Exists(Path||Name'.'Extension) /* Check to see whether the filename with the new */ If Ensure = 1 then /* extension already exists as another file... */ Do Toptext '"'Name'.'Extension'" already exists' Return /* Yes - Let the user know and move onto the next... */ End If Exists(Path||Name'.info') then Do Call Rename(Path||Name'.info',Path||NoExt'.'Extension'.info') End Success = Rename(Path||Name,Path||NoExt'.'Extension) If Success = 0 then /* Was the renaming successful ? */ Do Toptext 'Could not rename file "'Name'"' /* No - move onto the next... */ Return End Toptext 'Added 'Extension' extension to "'Name'"' /* All OK - Let the user know */ Return /* and move onto the next entry */ /*---------------------------------------------------------------------------------------------------------*/