File Type Detection

I have a application program which allows user to open text files. However, if a user rename a .xls file to a .txt file, my program will still open it and write to it, thus corrupting the file.
Other than checking the file extension, how can I determine a file is a text file or not?

That is a good idea! Do you mean I check each bytes to
see if it is between \u0021 and \u007E? or between
\u0000 and \u007F? Thanks a lot!Use an array of bytes and convert them to a String then step through each
Char in the string using
boolean aboolean = aChar.isLetterOrDigit()
and
boolean aBoolean = aChar.isWhitspace()
If you never get false you have text.

Similar Messages

  • Detecting file type in vba for word

    I have directories full of files on a Mac.  Most of these files are Doc files, some Txt files and some other types. Unfortunately the files don't have file extensions (not hidden but actually no file extensions).  On a PC in a macro I need to open
    these  doc files (from the Mac) and do some manipulations on the files and then save them.  I have a macro which works as long as all the files are Doc files so if I can detect the file type in my macro I can skip the non-Doc files and process only
    the Doc files.
    Is there a way in a vba for word macro to detect a file type other than by the file extension?  Or if that can't be done can I put error trapping on my Open statement that will catch an attempt to Open a non-Doc type file?
    Thanks
    Harry Spier

    If your code is running on Windows and you are in a position to install software on it, you
    may be able to get reasonably reliable detection using dsofile.dll, which you can get here:
    I really do not know whether it will work with files stored or create on Mac (and in any case, if these are old Mac .doc files, you may find that Windows Word cannot open them anyway.
    You need to
     - register the dll via regsvr32
     - in VBE, use Tools->References... to make a reference to"DSO OLE Document Properties Reader 2.1"
     - use code such as the sample below. 
    Option Explicit
    Function IsWordDoc(FullName As String) As Boolean
    ' FullName is the full path name of the file you want to check
    Dim objDocumentProperties As DSOFile.OleDocumentProperties
    IsWordDoc = False
    Set objDocumentProperties = New DSOFile.OleDocumentProperties
    ' or you can add dsoOptionOnlyOpenOLEFiles to the options and
    ' use error trapping to detect -2147217148
    objDocumentProperties.Open sFileName:=FullName, ReadOnly:=True, Options:=dsoOptionDontAutoCreate
    If objDocumentProperties.IsOleFile Then
    If objDocumentProperties.OleDocumentFormat = "MSWordDoc" Then
    IsWordDoc = True
    End If
    End If
    objDocumentProperties.Close savebeforeclose:=False
    Set objDocumentProperties = Nothing
    End Function
    Sub testIsWordDoc()
    Debug.Print IsWordDoc("c:\a\test.doc")
    Debug.Print IsWordDoc("c:\a\test.xls")
    End Sub
    You may also find that the value of the property I am checking varies and that you need to look at other things, such as 
    objDocumentProperties.SummaryProperties.ApplicationName
    but that value definitely varies according to the version of Word used to create the .doc, so you would need to discover what values it can have in a valid .doc.
    Peter Jamieson

  • Setting the file type in a file field

    Hi,
    I wonder if any body can help i am new to web application
    development, I am developing an asp application in dreamweaver 8,
    A few of my pages contain a file field which has a file
    browse button at the end of the field which works fine,
    now i want to set the default file type to *.pdf, Currently
    when i run my app in IE 7, when i click on the file browse
    button, the file browse dialog box appears but the default
    file type is *.* (All files), is it possible to set the default
    file type
    to pdf so that when the file browse dialog is displayed the
    default file type is *.pdf in stead of *.*.
    Thanks
    Fifo

    The OS just watch the extension of the file.Not always. If you create a word doc but name it with
    some other extension, the OS still can determine that
    it is a word doc.On which OS?
    if i take foo.exe and i rename foo.doc so my OSwill
    try to open it as a MS Word Document.Again, garbage in, garbage out.What you mean?
    If I create a MS Word Document for a file .doc that is not a real .doc and it is not able to read, i will just lose cpu time and a lot of memory.
    So it is important to understand if I need really to open MS Word watching what is the real file type
    Either way, you're going to be doing way too much
    work (and wheel-reinventing) if you're going to build
    your own detection scheme.In the SDK there is not any file type checker, and if eventually really exists an OS like you say that is able to read inside the file, i prefer to have my own Java class that do that work in a safe and opensource way.
    However in my first post i've given a site with some java code that do what I need, i just was asking if anyone know if there is any ready-to-work java class that is better for doing this work.

  • How to identify the file type in a safe way

    I need to identify the filetype of a file in my disc.
    I watched over internet and i've found this good site:
    http://filext.com/
    that supplys the "magic bytes" for many kind of files.
    I have also looked over internet for some ready class that identify different file types, and I have found FFident:
    http://schmidt.devlib.org/ffident/index.html
    Do you know any other Java package/class that is able to identify correctly the file types?
    Thank you,.

    The OS just watch the extension of the file.Not always. If you create a word doc but name it with
    some other extension, the OS still can determine that
    it is a word doc.On which OS?
    if i take foo.exe and i rename foo.doc so my OSwill
    try to open it as a MS Word Document.Again, garbage in, garbage out.What you mean?
    If I create a MS Word Document for a file .doc that is not a real .doc and it is not able to read, i will just lose cpu time and a lot of memory.
    So it is important to understand if I need really to open MS Word watching what is the real file type
    Either way, you're going to be doing way too much
    work (and wheel-reinventing) if you're going to build
    your own detection scheme.In the SDK there is not any file type checker, and if eventually really exists an OS like you say that is able to read inside the file, i prefer to have my own Java class that do that work in a safe and opensource way.
    However in my first post i've given a site with some java code that do what I need, i just was asking if anyone know if there is any ready-to-work java class that is better for doing this work.

  • CF9 - best way to restrict file type for uploads??

    Hello, everyone.
    We're using CF9 in both dev and production environments, with little chance of upgrading to CF10 anytime in the near future (it's my understanding CF10 does have a way of detecting a file mimetype that CF9 doesn't have.)
    What is the best way to restrict uploads to specific file types in CF9?  We just need to limit uploads to primary Office (doc(x), ppt(x), xls(x), etc.), PDFs, and gif/jpg (no bmps, pngs, etc.)
    Obviously, just detecting file extension is fruitless.
    Thank you,
    ^_^

    What about just using the accept attribute? That's what it's there for. Just something like:
    <cffile
    action="upload"
    filefield="fileContent"
    accept="application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-powerpoint, application/vnd.openxmlformats-officedocument.presentationml.presentation, image/gif, application/pdf"
    etc.

  • How to recognize file type (bytearray type)

    Hi,
    what ist the simplest way to detect file type or the type of byte[ ]? I mean, for example, how to detect if a "xyz.pdf" is a "really" PDF-File and not some Jpg with ".pfd"-extension.
    Thanx in advance
    vedran

    but there must be a easy wayIn general there is no requirement that a bunch of bytes belong to
    some unique "type". So there is no way to retrieve that type and, in
    particular, no easy way.
    If you want some pragmatic test (and I'm assuming that pdf was
    just an example - you want something general), you could have a
    look at the nix file command. It is open source and comes with
    a big set of useful files describing file headers. It is open source and
    can be seen, for example, here: ftp://ftp.gw.com/mirrors/pub/unix/file/

  • Determine file type

    How to determine file type given an input stream only?
    private String getFileType (InputStream inputStream) {
    return fileType;
    }

    But there must be some way to do thisWhy must there be?
    There may be "magic numbers" in the stream, or there may not be.
    The point was made in reply one that quite a few file types and that without some sensible choice about what options are going to be considered it could be quite infeasible.
    But it's worse than that. There will be more file types tomorrow than there are today. Unless you are happy with your software failing tomorrow (or have access to java.lang.crystal.Ball) it will be quite difficult to test for tomorrow's file types.
    But it's worse than that. A few minutes ago I created a file type to be used for blog entries on our intranet. Detect that one!
    But it's worse than that. There is no reason why a given stream should not produce a whole lot of bytes that can be validly interpreted by two different pieces of software, each for their own ends. In other words: one stream, two (or more) types.
    Again, why must there be some way to do this?

  • CustomEditor Extension - How to add support for a new file type...

    Folks,
    I'm trying to use the CustomEditor extension as a basis for a new editor that will work with an arbitrary extension (say ".foo").
    How do I tell JDeveloper that .foo files should be opened by my wonderful new extension?
    I've created a Node class called 'FooNode' to represent my .foo file. It extends DeployableTextNode and overrides the two public variables that appear to specifiy what file types this node represents:
        public static final java.lang.String EXT = ".foo";
        public static final java.lang.String EXT2 = ".bar";The relevent piece of code is in AnAddin.java and appears to be:
      public void initialize()
        EditorManager eMgr = EditorManager.getEditorManager();
        eMgr.register(this, new Class[] {/*XMLSourceNode.class,*/ FooNode.class });
      }This doesn't work - I can't get JDeveloper to recognize .foo files and bring up my editor. What am I doing wrong?
    David Rolfe

    From our development team:
    For the IDE to recognize a new file extension, it needs to be
    explicitly registered with the IDE framework. So the static
    final field named EXT isn't automatically detected. To
    register the extension (this is the JDev 10.1.3 API):
    import oracle.ide.model.Recognizer;
    Recognizer.mapExtensionToClass(".foo", FooNode.class);

  • Set file type associations in Adobe Bridge for Photoshop CS6

    Is there a way I can edit the registry so that in Adobe Bridge, under edit, preferences, file type associations, the jpg extension is forced to use the 32-bit version of Photoshop?  I can do it manually, but is there a registry key i can export to apply it to multiple computers?

    Yes, in theory, but it is generally not recommended. But that location would depend on what OS you are on. This video give the locations for the Photoshop files, Bridge would just be in a neighboring folder: http://tv.adobe.com/watch/the-complete-picture-with-julieanne-kost/how-to-reset-photoshop- cs6s-preferences-file/

  • Data Recover From Formatted Drive? What is the best program to use to get back Logic Projects and any other file type?

    I was in the process of reorganising my hard drives so I could RAID them however I managed to corrupt one drive and had to format it which meant I lost all my Logic Files and some other files. I managed to save a lot of files (mainly video files) before I had to format the drive but I need a Data Recovery service that will not alter anything on the hard drive and will put all the formatted files (regardless of the type) back for me so I can get the rest of the ones I need.
    Thanks in advance.

    What about folders and such?
    No. FS doesn't reconstruct folders. However, Data Rescue does, depending on how you use it. About the only thing in Data Rescue a Quick Scan ever seems to show you are files that are already live.
    So that leaves you with a Deep Scan, or a Deleted Files scan. The first pass of a Deep Scan will attempt to retrieve folders and files, along with their original names. The second pass only looks for file patterns. Like recognizing a Photoshop .psd file. It will recover it, but give it a nonsense name. A Deleted Files scan only results in nonsense names of recognized file types; no folders.
    What were you using File Salvage on? A hard drive?
    Yes, though you can use it on a flash drive, or any other mounted drive.
    At the moment it is estimating 289 hours remaining on a 1TB drive. Can it not go faster?
    No, both of the software mentioned are slower than molasses in January. When you delete anything in Windows, its file table entry simply tagged as deleted. So to unerase them, the tag is removed. That's why it works to quickly and easily (assuming you haven't already overwritten the data to be recovered).
    In OS X though, the whole idea of the underlying UNIX structure is all about security. It's not supposed to be easy to retrieve deleted items. When you delete items, their file table entries are erased. So the only way to find deleted items is to scour the entire drive for BOF (Beginning Of File) markers that don't have a matching starting block to anything that is in the file table.
    Another question, half the drive was empty. Will it fly over that empty space or will it sieve through it incase there was some files stored on it?
    If you use the Expert mode is FS, you can choose to do that:

  • File type in GUI_download

    Hi Experts,
    Whatis the coresponding file type for 'WK1 for WS_DOWNLOAD in GUI_DOWNLOAD?

    Hi ravi,
    1. Its the same WK1.
    2. U can check for yourself in the documentation of this parameter in se37.
    regards,
    amit m.

  • Removing obsolete file type associations from "Open With" menu

    Ever since I removed VMWare Fusion 3.x from my system, I've been unable to remove the Bootcamp file type associations that it created. For example, if I right-click on a PDF and choose Open With, this is a partial list of what I see:
    Adobe Acrobat Pro (default)
    Adobe Distiller (Mac) - Boot Camp partition (VMWare Fusion 3.0.0)
    Adobe Fireworks CS4
    Adobe Fireworks CS4 (Mac) - Boot Camp partition (VMWare Fusion 3.0.0)
    Adobe Illustrator CS4
    Adobe Illustrator (Mac) - Boot Camp partition (VMWare Fusion 3.0.0)
    Adobe Photoshop CS4
    Adobe Photoshop CS4 (Mac) - Boot Camp partition (VMWare Fusion 3.0.0)
    ...and on and on and on. 17 additional entries for Fusion for PDS's alone. This junk is driving me crazy.
    I've tried rebuilding the Launch Services database with MacPilot and Onyx (the recommended fix that I've found on the web), but the entries still are there even after restarting Finder and rebooting my iMac. I'm at a loss to figure out how to get rid of these.
    Can anyone help me?
    Thanks!

    They are stored in the LaunchServices database. You can give this a try, but no guarantees. If you no longer use VM Fusion then I suggest following the information below on uninstalling software.
    Rebuild LaunchServices Database
    Open the Terminal application in your Utilities folder. At the prompt paste in the following command in its entirety:
    find /System/Library/Frameworks -type f -name "lsregister" -exec {} -kill -seed -r \;
    Press RETURN.
    Wait for the Terminal prompt to return after which you can quit the Terminal.
    Uninstalling Software: The Basics
    Most OS X applications are completely self-contained "packages" that can be uninstalled by simply dragging the application to the Trash. Applications may create preference files that are stored in the /Home/Library/Preferences/ folder. Although they do nothing once you delete the associated application, they do take up some disk space. If you want you can look for them in the above location and delete them, too.
    Some applications may install an uninstaller program that can be used to remove the application. In some cases the uninstaller may be part of the application's installer, and is invoked by clicking on a Customize button that will appear during the install process.
    Some applications may install components in the /Home/Library/Applications Support/ folder. You can also check there to see if the application has created a folder. You can also delete the folder that's in the Applications Support folder. Again, they don't do anything but take up disk space once the application is trashed.
    Some applications may install a startupitem or a Log In item. Startupitems are usually installed in the /Library/StartupItems/ folder and less often in the /Home/Library/StartupItems/ folder. Log In Items are set in the Accounts preferences. Open System Preferences, click on the Accounts icon, then click on the LogIn Items tab. Locate the item in the list for the application you want to remove and click on the "-" button to delete it from the list.
    Some software use startup daemons or agents that are a new feature of the OS. Look for them in /Library/LaunchAgents/ and /Library/LaunchDaemons/ or in /Home/Library/LaunchAgents/.
    If an application installs any other files the best way to track them down is to do a Finder search using the application name or the developer name as the search term. Unfortunately Spotlight will not look in certain folders by default. You can modify Spotlight's behavior or use a third-party search utility, Easy Find, instead. Download Easy Find at VersionTracker or MacUpdate.
    Some applications install a receipt in the /Library/Receipts/ folder. Usually with the same name as the program or the developer. The item generally has a ".pkg" extension. Be sure you also delete this item as some programs use it to determine if it's already installed.
    There are also several shareware utilities that can uninstall applications:
    AppZapper
    Automaton
    Hazel
    CleanApp
    Yank
    SuperPop
    Uninstaller
    Spring Cleaning
    Look for them at VersionTracker or MacUpdate.
    For more information visit The XLab FAQs and read the FAQ on removing software.

  • File Type Associations

    Recently re-installed Adobe Photoshop CS6, Dreamweaver CS4 and Illustrator CS4 because I had considered not renewing my Adobe CC subscription. I decided to stay on CC one more year, but the previous version installs totally messed up my default file associations. I do not want to uninstall those previous apps.
    So of course I went to Bridge preferences and painfully changed them to the CC programs. The problem is if I want to open an .ai in Photoshop CC I used to be able to from one of the options in the flyout. Now I can only pick the default and all the other options are like Photoshop CS6 and Illustrator CS4. How can I change those other options populating the flyout without uninstalling the old apps?
    I can go to Photoshop CC and manually open it there, but that defeats the whole purpose of Bridge.
    I tried to change file type associations through Windows 8 file type associations but it won't let me do it there either.
    Thanks.

    Find a file you want to have associated to a different application in the Finder.
    Control-mouse click (or right click if you have a two button mouse) the file and select Open With's submenu Other...
    Find the application you want to open it with, and make sure in the Open With... file dialog box, you check "Always Open With" before selecting the application. Documents of that type will now always open with that specific application you chose.

  • File Type Associations Do Not Stick System-Wide CS4

    When I set File Type Associations for PSD, Tiff, DNG and Jpeg fles in Bridge CS4 so that my files will open in PS CS3 (and insure that the same file associations apply in Bridge CS3), this works as it should from within CS4 and CS3, but it is impossible to introduce a system-wide change in Mac OS 10.5.5 via File-Info. It always reverts to CS4 for these file types, if I try to 'modify all'. The same thing happened when I upgraded from CS2 to CS3.

    If File Type Associations are set properly in the Bridge preferences, the default setting can be made to open files in PS CS3, with CS4 installed. This works from within CS3 and CS4. However, it sometimes happens that one is in the Finder, and the default remains PS CS4, however much one tries (via File-Get Info) to modify the default system-wide settings so that these files open in CS3. In any event, a bit invasive. Of course, if I could get comfortable with the Adjustment Layer Panels, all this would be unnecessary, but for the moment, there appear to be too many clicks, and it is going to take some time, so I don't want to burn bridges. Perhaps there is also some ambiguity in my mind as to what the pointing finger in the new Curves dialogue box, much like a tolling bell, is trying to tell me.
    But thanks, once again Anne, for your good-natured help.

  • Bridge File Type Associations don't see my (2014) products?

    I have just updated Ps, Ai & Id to (2014) and uninstalled old versions (Win 7)
    Now Bridge has forgotten all my File Type Associations (no Adobe products in drop down) same is happening with my suitcase fusion 5 plugs, 2014 product not in plugs list
    Adobe is not installed in the default location, is on my second drive. all else is normal
    The result in this is that I can't 'Edit Original' or open any files without dragging from bridge into app.

    Has Ubuntu and Windows ever seen each other?
    You say "Ubuntu is apparently a linux platform...". not apparently - it IS a linux platform (are these your computers?)
    The first thing is to get them all into the same logical Workgroup.
    On PC: ControlPanel>System>ComputerName..jot down workgroupName.
    On ubuntu, the file/etc/samba/smb.conf is edited (might not need this yet).
    On Mac: Utilities> DirectoryAccess, Configure SMB/CFS...enter WorkgroupName in appropriate box.
    (then look into SystemPreferences>Sharing, and turn on File Sharing.
    In network utilities on the mac, have you been able to you ping these computers by their IP address? Have you been able to ping mac by number from Windows or Linux?
    This site might help, too along with the Apple link that the other user posted:
    http://www.ifelix.co.uk/tech/

Maybe you are looking for

  • Importing iTunes Music

    Hello. Is it still the case, with iMovie '11, that it's still recommended that we convert AAC music files to AIF when adding music? I recall in previous versions it WAS recommended for eliminating the audio track from breaking up after it was burned

  • How can I display more than one value in Calendar ? (2)

    Hi, I came across the "Calendar - Activity Monitor by month" in the HTMLDB admin section. This is exactly the view I like to develop asked earlier (the proposal was to work with concatination of fields). Can you provide for the source code used for t

  • Long string in pro*c

    Hi I have a pro*c program that execute some text with dbms_sql. something like EXEC SQL BEGIN DECLARE SECTION; VARCHAR input[32000]; EXEC SQL END DECLARE SECTION; EXEC SQL EXECUTE declare r varchar2(32767); idCursor integer; dummy integer; begin idCu

  • Changing fieldpoint settings programmatically?

    is there a way to change the channel settings from inside a running RT program? E.g. changing the gain of an input channel or switching from voltage to current input? So far I only see the option to configure the channels with MAX and once this confi

  • Bridge with two Cisco AP's

    Hello Everyone, So I have a scenario here and I'm wondering if this plan I have will work flawlessly or is there anything I have to lookout for? So I'm going to bridge two Cisco AP's 1260 and 3500, which have an 880 router on each side. (Currently I