Removing file extension using REGEX

                // User didn't add the XLS extension; add it automatically
                if (file.getName ().lastIndexOf (".") > 0)
                    fileName = file.getName ().toLowerCase ().replaceAll (".*$", ".xls");
                    System.out.println ("*** ALREADY HAS AN EXTENSION ***");
                    System.out.println ("Renamed to " + fileName);
                ...What I'm trying to do is remove a file extension from a string and add my own. For example, in my application, I'm checking to see if there is a period in the file.getName() string. If there is, I want to replace anything from the period on with nothing, but I don't think my regular expression is right.
If I type in "file.txt", I get:
*** ALREADY HAS AN EXTENSION ***
Renamed to .xls.xls
Basically, my regular expression is incorrect, but I don't see what I'm missing.

    private void saveFile ()
        useFileFilter (".xls", "Excel Files (*.xls)");
        String fileName;
        int returnVal = fc.showSaveDialog (this);
        if (returnVal == JFileChooser.APPROVE_OPTION)
            File file = fc.getSelectedFile ();
            if (file.getName ().endsWith (CustomFilter.getExtension()))
                // User kept the XLS extension
                fileName = file.getName ();
                System.out.println ("Saving " + fileName);
            else
                // User added their own extension; change it
                if (file.getName ().lastIndexOf (".") != -1)
                    fileName = file.getName ().replaceAll ("\\..+", "") + CustomFilter.getExtension();
                    System.out.println ("*** ALREADY HAS AN EXTENSION ***");
                    System.out.println ("Renamed to " + fileName);
                // User didn't add an extension; add it
                else
                    fileName = file.getName () + CustomFilter.getExtension();
                    System.out.println ("*** Saving " + fileName);
        else
            System.out.println ("User cancelled the dialog.");
    }I found that your regex works best in this case.fileName = file.getName ().replaceAll ("\\..+", "") + CustomFilter.getExtension();If I try to save a file as tEsT.tar.gz, my output is:
*** ALREADY HAS AN EXTENSION ***
Renamed to tEsT.xls.
If I used the other user's example:fileName = file.getName ().replaceAll ("\\.[^.]*$", "") + CustomFilter.getExtension();it wouldn't be correct. If I entered a filename such as tEsT.tar.gz, my output would be:
*** ALREADY HAS AN EXTENSION ***
Renamed to tEsT.tar.xls

Similar Messages

  • [JS] Need Help Removing File extension (in CS2 and CS3)

    Hello All.
    I have a menu in a dialog that needs to list some file names, but without their file extensions (which will always be .txt in my case). The following is some code that successfully does this in CS3, but I also need it to work in CS2. Do you have any other ways to do this? One code that works in both versions (CS2 and CS3) is ideal.
    myNameWithoutExtensionFunction = function( myNameWithExtention ) {
    myNameWithoutExtension = myNameWithExtention
    myEndOfFileName = myNameWithoutExtension.lastIndexOf( "." )   // get the last period (.) in the filename
    if ( myEndOfFileName > -1 ) {
      myNameWithoutExtension = myNameWithoutExtension.substr( 0, myEndOfFileName )
    return myNameWithoutExtension
    Thanks in advance.
    Dan

    I realized my mistake. The above code works just fine in CS2. My mistake was elsewhere. The name I was sending to this function wasn't being recognized by CS2. Once I corrected that and sent a valid name to this function it worked. So in case someone needs to remove file extensions, feel free to use the above function!

  • How to remove file attachments using the SDK

    I am looking for ways to programmatically remove file attachments from work items.  If I recall correctly, the system only keeps the file for as long as the relationship exists, so that, in theory, the file is deleted from the database a soon as the
    relationship is removed.
    I found this
    Using the SDK to Create and Edit Objects and Relationships Using Type Projections
    Is this the only way or are the other, simpler ways for deleting relationships and/or file attachments?
    Is this something I could do with the Orchestrator Remove Relationship activity?
    A little background on this question: I have multiple different teams with varying data retention requirements for Service Requests.  My longest requirement is 3 years (audit) while most teams only require 90 days.  I was looking to add in some
    jobs for some more aggressive file attachment grooming to keep the database smaller.
    Thanks.

    The relationship is defined as a membership/containment relationship. So, yes, if you delete the relationship, the file attachment (and the associated blob) are deleted as well.
    Based on the background you described, I'm assuming you identify a bunch of work orders whose files you want to delete if they're older than X. So, for instance "Work Items with Y team; delete file attachments older than 90 days", "Work Items
    with Q team; delete file attachments older than 3 years". Is that right?
    If so, you don't necessarily need to delete relationships specifically...you can simply delete the file attachment objects which will delete the relationship, the file attachment object, and the associated blob (the file itself in the database).
    Using the SDK, you will not need type projections for this. You'll only need the work item object(s) (an incident or service request or whatever), the GetRelatedObjects<>() method, and an IncrementalDiscoveryData object.
    So, after you get all of the appropriate work items, you can use the following snippet to delete their file attachments if the attachments meet your age requirements
    //Connect to the management group
    String strMySCSMServer = "<my mgmt server>";
    emg = new EnterpriseManagementGroup(strMySCSMServer);
    IncrementalDiscoveryData idd = new IncrementalDiscoveryData();
    ManagementPackRelationship relWorkItemHasFileAttachment = emg.EntityTypes.GetRelationshipClass(new Guid("AA8C26DC-3A12-5F88-D9C7-753E5A8A55B4")); //System.WorkItemHasFileAttachment
    //Get the work item's related file attachments using it's Id
    Guid myWorkItemGuid = new Guid("<some work item guid>");
    IList<EnterpriseManagementObject> lstFileAttachments = emg.EntityObjects.GetRelatedObjects<EnterpriseManagementObject>(myWorkItemGuid, relWorkItemHasFileAttachment, TraversalDepth.OneLevel, ObjectQueryOptions.Default);
    //Loop through each file attachment
    foreach (EnterpriseManagementObject emoFile in lstFileAttachments)
    //Determine its age
    DateTime AddedDate = (DateTime)emoFile[null, "AddedDate"].Value;
    TimeSpan FileAttachmentAge = AddedDate.Subtract(DateTime.Now);
    //Prep the file attachment for deletion if it's old enough, in this example, older than 90 days
    if (FileAttachmentAge.Days > 90)
    idd.Remove(emoFile);
    //Submit the deletions to the database.
    idd.Commit(emg);

  • Bridge removing file extension after batch rename

    Hi All,
    I've been having trouble with what appears to be a problem with Bridge in Photoshop CS2. I'm well aware this is an older version but, in this case, I don't think that should matter. Here is my situation:
    After batch renaming jpeg files, I've had a problem with Bridge simply stripping off the file extension on all the newly renamed files. This never happens right away...always later. In other words, I'll batch rename a folder full of photos without issue, note that the rename was successful, and then return to that same folder a short time later to find white thumbnails and missing file extensions. This has happened exactly the same way on two different computers - and always with the delay.
    This is getting to be very annoying. Has anyone had or heard of a similar issue? Thanks very much...

    First use the menu tools / cache / purge cache for folder, if still in trouble restart Bridge holding down option key to refresh preferences

  • 'save as' dialog removes file extensions under Snow Leopard. How do I stop this?

    When I save a web page I sometimes use an existing file name as a template to reduce the amount of typing and chance for errors. Before I upgraded to 'Snow Leopard' the file type (.html) was on the file name. Now it is removed. This doesn't happen in Safari. How can I stop this from happening?

    Hi hbman-
    Here is a Support article on how to troubleshoot file download and save issues:
    [[Unable to download or save files]]
    Hope that helps!

  • Question about file extension - using email delivery options in 12.1.3

    So, we had 12.1.1 and we have some existing XML Publisher reports.
    Now we've upgraded to 12.1.3, and there is a new option when running a concurrent request called "Delivery Options".
    This allows, among other things, to deliver the output to an email address.
    In testing this, I tried running a report that typically outputs to Excel....however when it sends the email (again, not using a bursting control file, but the delivery options in the concurrent request), the attachment comes over with an extension of .EXCEL instead of .XLS
    Does anyone know where I can change that extension?
    thanks!
    -jerry

    This seems to be a bug - pl see MOS Doc 1554605.1
    HTH
    Srini

  • How to find the file type without the file extension using indesign javascript (.jsx)

    hi,
    How to identify the file type (eg: InDesign or Quark) without knowing their file type. How can we find what kind of file is that??? without their extension like ('.indd','.qxd') before import to the document...

    Hi subha_oviya,
    Take a look at the file filtering section in the InDesign CS3 sample script ImageCatalog.jsx to see how to look for file types. I'm assuming that you're using InDesign CS3, and that you're using the Mac OS--you didn't say.
    Thanks,
    Ole

  • Change the file extension

    Hello everybody,
    I want to change the file extension using java. For example the file is xyz.dat it will change to xyz.data. Is there any method which will do this task.
    smh

    http://javaalmanac.com/egs/java.io/RenameFile.html

  • Hello people, i need help to open a PX file extension, anyone?

    Have you tried "Paradox" by corel? that's what makes one type of .px extension apparently - but it seems there are several different types of .px files/extensions, used by different programs.
    Where/who did you get the files from - can you check with the user to see what they use?

    I'am able to open it with Notepad but i would like to know if there is any program that can open it, thanks.
    This topic first appeared in the Spiceworks Community

  • Can the file extension be removed when using the File Special Field?

    I placed a Special Field on the top of my topics that gives
    me the filename for that specific topic. I used the Insert >
    Field > Special Field > File and the File Name is inserted
    where I want it. The problem is that i don't want the file
    extension to show, just the name. I can't figure out how to do
    this...Any suggestions....anyone? Maybe a Script or an applet? Any
    input will be greatly appreciated...

    Thank you for your response. I did try something similar to
    what you suggested but the problem is that whatever I modify it
    automatically puts it back like it was as soon as I try to save it.
    This is probably because I used the Insert Special Field commands
    from the Menu. It automatically places this on the code:
    <!--kadov_tag{{<variable name=file
    x-format=default
    x-value=017.htm>}}-->017.htm<!--kadov_tag{{</variable>}}-->
    Where 017.htm is the actual name of the file for the specific
    topic. This means that it's apparently doing this on the background
    somewhere I can't see and inserting the value on the code for the
    topic...
    I hope that made sense! Again, I thank you in advance for any
    suggestions...

  • Q: InDesign Extension could not be removed from file system when it was removed in Extension Manager

    <body>
    <p>All files of an ordinary extension will be removed from file system when this extension is removed in Extension Manager. But InDesign extensions with <tt>"plugin-manager-type"</tt> attribute in mxi file are special. Extension Manager will NOT remove files of this kind of extensions from file system when removing these extensions. Instead, Extension Manager will use other way to tell InDesign not to load these removed extensions when InDesign is launched. If you want to make your InDesign extensions removable, you can just remove <tt>"plugin-manager-type"</tt> attribute from the mxi file when you generate an extension.</p>
    </body>

    Thanks for the help. Yes that addressed the issue.
    On a side note, the tutorial I followed was the one that came with the plugin. Specifically I'm referring to the following file:
    //<eclipse_path>/plugins/com.adobe.cside.html.docs_1.0.0.201307260955/doc/getting_started/ Create_Your_Own_HTML5_Extension_In_5_Minutes.htm
    This is the HTML page for the "Create Your Own HTML5 Extension In 5 Minutes" walkthrough. It makes no mention of changing "PlayerDebugMode". I downloaded the eclipse plugin from the following link:
    http://labs.adobe.com/downloads/extensionbuilder3.html
    Is there a more up to date plugin? Where is the documentation that references changing the settings you mentionned?

  • How do I change or remove default apps for a given file extension (in Terminal?) without munging date modified on all my old files?

    When a program is installed, it seems to be able to do it (sometimes inappropriately if it hijacks file associations without asking) so why can't I?  This is for 10.4.
    Specifically:
    1. Since installing an HP wireless printer, HP not only tries to install a bunch of sales-ware on your machine that you have to carefully opt out of (annoying, but not a problem if forewarned), it changes the default file association for a number of basic file types, listing all sort of existing files as HP printer files. Using Get Info to change the default file type association globally causes it to mark ALL the files of that type as newly updated, munging the file metdata (which HP did NOT do). Most of the stuff on our computer is sorted by last modified, so if there is a way to fix this in Terminal (to simply fix or remove the HP default tag) without changing the date the file was modified, it would help. Note that uninstalling the program that created the default would do this, but I obviously can't do that (and reinstalling HP would have the same effect). So there has to be another way, right?
    2. Since updating iTunes to v.9 a while back, every mp3 is marked as an iTunes file even though iTunes has NO multiple library capability without a wonky reboot using the option key, meaning that if I click on an mp3 downloaded since last update of iTunes, it opens automatically in iTunes and gets added to the SOLE itunes library without asking. (There is no way to toggle between multiple libraries or archive media in separate folders; iPhoto has a similar problem. (Has this been fixed in the latest version of iTunes?) In comparison, Quicktime starts up immediately and does not attempt to create a playlist just because you opened a file and listened to it.
    (The iTunes playlists are simply subfolders of the single main library -- and you can't create a new library without doing a wonky procedure by clicking option during startup and telling iTunes to forget where its library is located (includin everything in it) and look up an entirely separate one by hand. So any mp3 file downloaded recently is uploaded to iTunes if you click on it. This wouldn't be problem if it didn't automatically add it to the sole iTunes library just because you clicked on it.)
    Besides, all my old mp3s are Quicktime files and they are all archived by date modified. To its credit, ITunes, unlike HP, does NOT hijack older files already on disk and remark them as iTunes files. It only marks newly downloaded files as such.  But if I try and change file association for FUTURE mp3 files using Get Info > "use this program for all files of this type", it munges the file metadata (date modified) for all existing files!
    Note that in HP case, it apparently does it at the file exchange preference level (or whatever it's called) since the OS then recognizes every file of those types as an HP file. In the iTunes case, it only does it if you download a new media file or open an existing file in iTunes, but again without changing the date it was last edited.
    Since these programs are able to change the default file association without changing the date the file was last edited, it should be reversible in Terminal, correct?  Why does it change "date modified" when you try and correct metadata using Get Info (or sometimes just by clicking an enclosing folder?) Date modified should be a record of when a file itself was edited, not when it was renamed, or other metadata. Otherwise stuff can't be sorted correctly.

    The unix commands you need are:
    GetFileInfo
    SetFileInfo
    and maybe find
    for cryptic details use the man command
    Macintosh-HD -> Applications -> Utilities -> Terminal
    man SetFileInfo
    You may use the SetFileInfo command to set the file type & the program which will open the file.
    # This little gem will do a get info on all files in a directory.
    mac $ ls  | xargs -I {} GetFileInfo "{}"
    file: "/Users/mac/playdoc/oddadocodd"
    type: ""
    creator: ""
    attributes: avbstclinmedz
    created: 05/01/2011 14:53:22
    modified: 05/01/2011 14:53:22
    file: "/Users/mac/playdoc/one.docx"
    type: ""
    creator: ""
    attributes: avbstclinmedz
    created: 05/01/2011 13:57:48
    modified: 05/01/2011 13:57:48
    file: "/Users/mac/playdoc/oneLineFile"
    type: "TEXT"
    creator: "!Rch"
    attributes: avbstclinmedz
    created: 05/07/2011 14:27:17
    modified: 05/07/2011 14:27:17
    file: "/Users/mac/playdoc/oneLineFile.txt"
    type: "TEXT"
    creator: "!Rch"
    attributes: avbstclinmedz
    created: 05/07/2011 14:27:49
    modified: 05/07/2011 14:27:49
    file: "/Users/mac/playdoc/three.docx"
    type: ""
    creator: ""
    attributes: avbstclinmedz
    created: 05/01/2011 13:58:03
    modified: 05/01/2011 13:58:03
    file: "/Users/mac/playdoc/two.docx"
    type: ""
    creator: ""
    attributes: avbstclinmedz
    created: 05/01/2011 13:57:56
    modified: 05/01/2011 13:57:56
    file: "/Users/mac/playdoc/weirder.doc.docx"
    type: ""
    creator: ""
    attributes: avbstclinmedz
    created: 05/01/2011 14:50:03
    modified: 05/01/2011 14:50:03
    # well, ! is a funnie character so we escape it.
    mac $ SetFile -t TEXT -c \!Rch two.docx
    mac $ GetFileInfo two.docx
    file: "/Users/mac/playdoc/two.docx"
    type: "TEXT"
    creator: "!Rch"
    attributes: avbstclinmedz
    created: 05/01/2011 13:57:56
    modified: 05/01/2011 13:57:56
    mac $
    mac $ date
    Sat May  7 14:40:56 EDT 2011
    mac $

  • I tried opening my Mac files to windows by using Macdriver 8, however upon opening the file my previous mac folders were converted to windows shortcuts and upon returning to my mac pc, all my folders has a .lnk file extension which I cannot open.

    I tried opening my Mac files to windows by using Macdriver 8, however upon opening the file my previous mac folders were converted to windows shortcuts and upon returning to my mac pc, all my folders has a .lnk file extension which I cannot open. Need help very badly since the hard drive I use is the only back up I have for my very old pics. Thank you...

    Backup with cloning software your HD to have an exact copy of it as it is.
    Use this methodology to recover your partition.
    Have fun,
    Leo

  • Firefox can't read any Bookmark that was imported from my PC with file extension .url. Safari reads them fine. Is there a fix, so I can use Firefox instead of Safari? Many thanks if so. I have the latest version of Firefox

    Firefox can't read any Bookmark on my Mac that was imported from my PC with file extension .url. Safari reads them all fine. Is there a fix, so I can use Firefox instead of Safari? Many thanks if so. I have the latest version of Firefox
    == URL of affected sites ==
    http://anysite.url
    == User Agent ==
    Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7

    Hello JF.
    I don't think that extension is supported. I believe Firefox can only read .json and .html.
    You may want to read this though:
    [http://support.mozilla.com/en-US/kb/Importing+bookmarks+and other data from Safari Importing bookmarks and other data from Safari]

  • Why do the file extensions (.jpg .gif .png) no longer appear when I click on a previously saved image to use that image's file name (particularly important when saving a series of images using the same root name)?

    I save a lot of images using firefox, often times from a large batch or series of images. It used to be that I would click on a previously saved image and the entire file name including the file extension (i.e. image_example.jpg) would appear in the "save as" line. Now when I click on a previously saved file, the file name appears without the file extension (i.e. image_example). Which means I have to manually type .jpg every time. For a large collection of images that I am hoping to use the same root file name and then add chronological numbers at the end, this has become incredibly frustrating, especially as it is a previously unnecessary task.
    I am using a new Macbook Pro and maybe there's something Apple related to this...? It did not happen on my old PowerBook G4. I have file extensions turned on in System Preferences.
    It should be noted that I have searched high and low and have even gone into the Apple Genius Bar where they were just confused as I was and of course ended by urging me to use Safari (shocker!) as it has all kinds of new extensions and bells and whistles. I seriously feel alone on an island with this dumb, hard to google problem. Thanks so much for any help anyone out there might have.
    I mean: is this as simple as changing a setting in about:config?
    Your assistance is greatly appreciated.

    Thanks for your response Mylenium, however like I mentioned multiple times, I did change all of my trackpad/scrolling settings in system preferences.  And if I wanted to use a normal mouse (or a tablet), I would've gotten an iMac instead of a MacBook Pro.  I travel often and work all over the place, not always with access to a decently sized workspace that would be required for using a mouse or tablet.

Maybe you are looking for

  • How do I set my TV as a preview display in Final Cut Pro?

    I have a 30 inch LG Flatscreen connected via hdmi cable to my mac pro, but all I am able to do is mirror the two displays otherwise it is basically in active with a background only. I want to use it as a preview when I view my videos in final cut. I

  • Unable to convert the RDF layout to RTF Layout for cross tab report

    Hello All, I have a RDF, which has cross tab layout. For this I need to create RTF template. I have the XML file. I'm not able to get the cross tab report in RTF as RDF. Below is the part of XML data. Pleaes let me know how do i achive this. <?xml ve

  • Accounting Entries for Consignment - with CIN Entries

    Following are steps in consignment sale: 1. Consignment Fill-Up (From factory to consignment agent) 2. Consignment Issue (From consignment to end customer) 3. Consignment Pick up 4. Consignment Returns I searched in SDN forums. It says that there is

  • Error Consuming Web Service:Unsupported xstream found:("HTTP Code 200:OK")

    I am trying to consume a web service from an Outbound Proxy. I am getting the following error message:- Unsupported xstream found: ("HTTP Code 200 : OK") This is a System Exception generated while I call the Outbound Proxy. Kindly let me know what co

  • Master/Detail problem: Infinite loop with display items

    Hi, I have a strange problem in Oracle Forms 6.0.5.35.3. I create a master block and a detail block with correct relationship between them. -> When the detail block contains at least one 'Text Item' everything works well. -> When the detail block onl