How to strip file extension off a filename NSString ?

To retrieve file extension from NSString, we use "pathExtension".
To retrieve the filename from NSString without the extension we use ?

9 views any nobodies helping ?
Oh well...
I've created this function to achieve this:
-(NSString *) returnfile_name_without_theextension:(NSString *)filename
NSString *filename_extension = [filename pathExtension];
NSInteger filenameextensionlength = [filename_extension length];
NSInteger filename_length = [filename length];
filename_length = filename_length - (1 + filenameextensionlength);
return [ filename substringWithRange:NSMakeRange(0, filename_length) ];
Hope someone might find this useful.

Similar Messages

  • Stripping File Extensions

    I need help stripping file extension.
    (Example)
    filename = filename (Good)
    filename.extension needs to become just filename
    filename.sub.extension needs to become filename.sub
    I need a function that will achieve this, because when saving
    files, I need to copy some additional files over that need to have
    the same name as the saved file. This is the last bug I need to fix
    in my app.

    You're awesome. Thanks so much for the example.
    Now I will be able to finally pull my application out of Beta
    and into Release Candidate.

  • How to display file extensions

    Hi,
    I'm trying to get our Sharepoint 2013 server to show file extensions again and I've had no luck so far. I've been able to add an extra name column that shows the file extension (like ), but that name is not clickable anymore so I've ended up with one name
    that's a link and the same name next to it. This doesn't look good, especially when the users pick overly long file names.
    This (http://social.technet.microsoft.com/wiki/contents/articles/11161.how-to-display-file-extensions-in-a-sharepoint-document-library.aspx) seems to apply to Sharepoint 2007 only. I'm not sure which onet.xml file they mean and the default file has several
    occurences of "Name=”Created_x0020_Date”", or how adding
    Name=”File_x0020_Type”/> without an extra opening bracket would work.
    I've also found and tried this solution: http://social.technet.microsoft.com/Forums/sharepoint/en-US/59c15eee-9116-4aa1-8d16-32cd361c9a2f/show-file-extensions-in-document-library?forum=sharepointcustomizationprevious
    >>3. Edit the WebPartPages:XsltListViewWebPart so that the link contains the extension.
    >>a. Open SharePoint Designer and click on the desired document library.
    >>b. Open the View you want to change, which in most cases is "All Documents".
    >>c. Find the line that looks like this:
    >><xsl:value-of select="$thisNode/@FileLeafRef.Name" />
    >>d. Edit the line to look like this:  (the xsl:if tests to see if the suffix is not blank and then displays a '.' and the suffix)
    >><xsl:value-of select="$thisNode/@FileLeafRef.Name" /><xsl:if test="$thisNode/@FileLeafRef.Suffix!=''">.<xsl:value-of select="$thisNode/@FileLeafRef.Suffix" /></xsl:if>
    This doesn't seem to work with Sharepoint 2013 because the line <xsl:value-of select="$thisNode/@FileLeafRef.Name" /> doesn't seem to exist. Are there any other suggestions on how to get the file extensions to show?
    Thank you.

    Hi
    use these functions
    RIGHT (Text, Number)
    Return X characters from the right
    RIGHT(“The Quick Brown Fox”, 5)
    n
    SEARCH(Text1, Text2, Num)
    Returns the index of Text1 within Text2,starting the search at index Number
    Formula should be
    right([Name-column],search[".",[Name-column],1))
    More info regarding calculated columns
    http://junestime.wordpress.com/2013/02/12/sharepoint-calculated-column-formulas/
    Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.

  • Mail.app Stripping File Extensions

    Greetings,
    I have had a very odd issue with Apple Mail stripping away file extensions from the end of attachments. Several folks I send to have issues opening these attachments and have to add the suffix onto the end of the filename (and yes they were on the end when sent). They are using both Macs and Windows boxes.
    I have tried to correct the issue in numerous ways including:
    - Defaulting Mail to send Windows friendly attachments
    - Defaulting my OS to always show file extensions
    - Trying numerous SMTP servers
    - Trying both my .Mac account and Earthlink account
    - Using different ISPs to send on all of the accounts and servers listed above
    - Sending in both RTF and plain text messaging
    The only way I have been successful in retaining the suffix has been to send through both the Earthlink and .Mac webmail services. The test file I have been using then arrives with no issues.
    All of the above makes me pretty sure it is a Mail.app issue. I am about to install Entourage (ick) but would prefer to find a solution. After lots of searching I am throwing it out there to see if anyone else has had the same issue.
    Any thoughts?
    PPC iMac and MacBook Pro   Mac OS X (10.4.10)  

    OK, here is the latest. Anyone else feel free to pipe in with possible solutions!
    - Sending to a Mac and receiving in Mailsmith from Mail.app results in the file extension being stripped away. The person I sent to has no issues with anyone else sending her files
    - Sending to the same Mac and using Mail instead of Mailsmith results in the extension being preserved.
    - I set up Outlook Express on my Parallels partition and it seemed to preserve the extension when I sent it from Mail.
    So it looks like there is some issue with Apple Mail and some e-mail clients. The ones I know I have had problems sending to are Mailsmith on Mac and Goldmine on Windows. At this point I am thinking it is not a server based problem.
    If anyone has any possible solutions I would appreciate the input.

  • How to assign file extension and custom icon to executable?

    Hi all,
    I was reading an old thread about this issue:
    http://forums.ni.com/ni/board/message?board.id=170&thread.id=116925 
    I need to try to do this.  My application uses a custom file extension (i.e. .abc).  Upon installation I would like to:
    1.  Assign My App and custom icon to the file class (extension .abc).
    This could be done by manipluting the registry (http://msdn.microsoft.com/en-us/library/bb776856(VS.85).aspx)?  This could be a problem with Vista s unless registry operations occur during installation any changes are placed in a VirtualStore, correct?
    2.  Enable the double-clicking of .abc file type to pass the data in the file to my VI (exe). 
    According to the File Handling Guidelines of Jean-Pierre Drolet (http://www.openg.org/tiki/tiki-index.php?page=File+Handling+Guidelines) the best way to do this may be using LabVIEW as an ActiveX server.
    I know that when I build an executable (or installer?) there is the option to enable LabVIEW to act as an ActiveX server.  This much I know I need to do.
    I thought I would open this discussion again as others may be interested and there doesn't appear to be a completely clear solution available.  Please do contribute where you can.
    Cheers,
    Battler.

    battler. wrote:
    My application consists of Event Structure.
    How to register for ommand line event so that when a user double-clicks on a .abc file I can handle the opening of it?
    This needs to work (the files need to open) not only when the application is closed but also when it's already open.
    Anyone have ideas? 
    The solution to that is to implement a DDE server in your application (and add DDE entries to the registry on installation). There are still DDE functions in LabVIEW vi.lib\Platform\dde.llb but they are considered depreciated and have been removed from the palette, also because Microsoft is trying to tell everyone that DDE is depreciated and sort of unsupported too. But it is still the mechanisme to pass actions from the shell to running applications.
    I hesitate to send you over to lavag.org where there have been some discussions about this years ago. If you go there you would do good to employ a friendly attitude. That board is run all by enthusiasts and idealists and they are all great folks but react not very friendly to people with an attitude.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • How to set file extension?

    Hello there,
    I have added the ablility of saving the data in my program. I was wondering how do I restrict the file extension when the user wants to save the file?
    What I mean is right now, when a user saves the data to file, they can choose the file name and the file extension. I do not want to allow them to choose file extension. I want to have a predefined extension, for example .usr or .dat.
    I have seen this in many applications but I do not know how to implement this. I would appreciate it if someone could help me.
    Thanks for your help!

    How you are getting the fname from the user has an impact on how you do this, but not what needs to be done. What is required to have something that takes the fname from the user and parses it, extracting a fname. Once you have that, just append the extension that you want and save the file.

  • How to include file extensions in contacts?

    When printing contact sheets from the Print module I don't manage to have the file name inclusive of file extension under each thumbnail (e.g. Maria.jpg); so far I only managed to have the file name without the extension (e.g. Maria). Any idea how to do it?

    F-
    <br />
    <br />I doubt it's impossible, but why would you choose to do this? I we know, perhaps another method may suffice.
    <br />
    <br />
    <span style="color: rgb(102, 0, 204);"></span>
    <font br="" /></font> color="#600000" size="2"&gt;~~ John McWilliams
    <br />
    <br />
    <br />
    <br />MacBookPro 2 Ghz Intel Core Duo, G-5 Dual 1.8; Canon DSLRs

  • How to validate File extension.

    Hi all,
    Can anyone suggest me any Function Module to validate a file extension while selecting the Filename at popup window.
    thanx
    Rakesh

    Hi,
      If you are using upload FM, fill up the following parameters..If you want to filter the data by certain extension.
      Hope this works...
    FILETYPE                        DAT   
    ITEM                                  
    FILEMASK_MASK                   *.xls 
    FILEMASK_TEXT                   *.xls 
    FILETYPE_NO_CHANGE              X     
    THanks,
    Naren

  • How to Hide File Extensions in URL

    Hello Again!
    I've tried to edit my .htaccess file to hide file extensions in my URL, but nothing I try works. I get "Page Not Found" when I try to remove the .html from my pages. Here is the code I have used:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html !-f
    RewriteRule ^{.*}$ $1.html
    I've also used
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^{.*}$ $1.html [L,QSA]
    Neither worked.
    Any thoughts would be helpful! Thanks!
    K

    When you save the document there is a check box in the save window that gives you the option to hide the extension. I've checked this for both Pages & Word. I can't be certain that all applications give this option.
    You can of course delete the extension name from individual files already on your computer by selecting the file name as if editing the name and just deleting the extension part of the name.
    Neville

  • How to hide file extension on finders symbolic view?

    When I switch the finder's view to symbolic the files view turns to an icon or minimized first page of the file's content. In some cases the file extension is displayed at the bottom of this symbol. E.g. files of type PDF always show the 3 letters PDF at the bottom of the small preview image. Files of type PKG don't show it.
    Is there a way to change this behaviour? Changing it in the finder's prefrences only affects hiding or showing the file extension in list view.
    Thanks for any advice!

    I tried it and it didn't look like it took effect. I switched folders and cam back to the first one I looked at and the extensions were showing.
    It may just need time to redraw the view.

  • How to backup file based on the FileName

    Hi SAP,
    I have a simple scenario in which I have to backup the files to the specific folder depends on the file name.
    FTP.............. XI ................ FTP
    Sender File : XXXXX_INXXXXXXX.xml
                         XXXXX_PHXXXXXXX.xml
                         XXXXX_THXXXXXXX.xml
    If Sender File char 7th and 8th = IN then it should go into the folder called DGE008\IN\Inbound
    If Sender File char 7th and 8th = PH then it should go into the folder called DGE008\PH\Inbound
    If Sender File char 7th and 8th = TH then it should go into the folder called DGE006\TH\Inbound
    Is it possible to do it with Integration Directory Only with FCC or Variable substitution because I really don't want to do Integration Repository.
    The other option I have got is to do the complete scenario with IR and ID and in the mapping used dynamic configuration.
    I have tried the complete scenario with IR and ID but unfortunately I am stuffs with dynamic configuration
    I am getting very silly error which is mentioned below.
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
    String fname = conf.get(key);
    String Country = fname.substring(7,2);
    If (Country == "IN")
    String Dirname="DGE008\"IN\"Inbound";
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","Directory");
    conf.put(key,Dirname);
    Else
    String Dirname="DGE008\"PH\"Inbound";
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","Directory");
    conf.put(key,Dirname);
    return "";
    Error
    Function getFileName, Line 11:
    ';' expected
    ^ 1 error
    I have checked everything but don't know why I am getting this error. could you please check and let me know.
    Thanks,

    Hi Hareen,
    Your code have is wrong and got so many mistakes which I rectified but still it is not working and I am getting the mapping error.
    Thanks for your help.
    Correct Code
    String filename,country, dirname=" ";
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey file_key =DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
    DynamicConfigurationKey Dir_key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","Directory");
    filename=conf.get(file_key);
    country = filename.substring(6,2);
    if (country.equals("IN") || country.equals("PH") || country.equals("TH"))
    dirname="/DGE008/" + country + "/Inbound";     
    conf.put(Dir_key, dirname);
    return "";
    *Error*
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    - <!--  Request Message Mapping
      -->
    - <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="">
      <SAP:Category>Application</SAP:Category>
      <SAP:Code area="MAPPING">EXCEPTION_DURING_EXECUTE</SAP:Code>
      <SAP:P1>com/sap/xi/tf/_mm_iso20022_to_ext2002_FTP_Back~</SAP:P1>
      <SAP:P2>com.sap.aii.mappingtool.tf7.MessageMappingExceptio</SAP:P2>
      <SAP:P3>n: Runtime exception when processing target-field</SAP:P3>
      <SAP:P4>mapping /ns0:Document; root message: Exception:[j~</SAP:P4>
      <SAP:AdditionalText />
      <SAP:Stack>Runtime exception occurred during application mapping com/sap/xi/tf/_mm_iso20022_to_ext2002_FTP_Back; com.sap.aii.mappingtool.tf7.MessageMappingException: Runtime exception when processing target-fieldmapping /ns0:Document; root message: Exception:[j</SAP:Stack>
      <SAP:Retry>M</SAP:Retry>
      </SAP:Error>

  • How to preserve file extension on rename?

    So, my little First World Problem:
    On Snow Leopard I was very used to pressing enter and renaming a file by simply typing a new name while preserving the extension. Now I've noticed that in Lion when you press enter and start typing the new name, you'll have to type in the extension too. Is this changeable?

    No, the behavior in Lion should be the same.
    I just tested it and "return" highlights the name and leaves the extension.

  • How to create encrypted File Extension??

    hi Folks
    i'd ilke to ask how to create file extension and how encrypt this extension??
    to make my question clear suppose we develop a word proceesing Application i would like this Application produce let say ".kad" when saving it and how to make this extension ".kad" encrypted meaning that we couldn't open the file unless my Application is existing.
    can anyone help me or give a tip to start of the way!!!!!!!!
    thnx

    Hi eng_kadry,
    if a little confusion is enough for you can use just a binary format, i.e. do not store readable text, but compacted binary information.
    If you really need to encrypt your data have a look at JCE (Java Crypto Extension) which provides various encryption algorithms.
    Note: You can't encrypt a file extension you encrypt the file. You can't prevent anybody opening the file with a hex-editor, but if you use binary or a really encrypted format he/she won't be able to make any sense out of it.
    Another note: Be aware that your program will always contain everything it needs to decrypt the files, so if anybody goes through the pain of decompiling your program he/she will be able to use the files and you can't prevent decompilation
    regards
    Spieler

  • Windows 8.1 File Extensions and Show Hidden Files Always showing

    Dear sir,
    It's been an on and off problem for me since my windows 8.1 sometimes like to show it all whether it's the extensions of the file or even the file itself and it doesn't accept my command on not showing it. I have a bitdefender 2015 always up to date so my
    guess is that could not be a virus please help.

    Hi,
    How about uncheck file extension option? In addition, follow the screenshot below and make your settings same with main.
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • File extension getter

    Is there a method in the API that will get the file extension off of a file name so that I can filter out certain ones. I'm providing an example just in case I'm using the wrong terminology, which could be why I'm having trouble finding it in the API.
    ex: MyProgram.java
    and then I only want to print it to the screen if it has the java extension.

    "Extension" isn't a cross-platform concept, so Java
    hasn't gone out of its way to support it. Follow
    walken16's suggestion of writing your own.
    (It's trickier than you might think. Watch out for
    edge cases like ".net" and "Finally." and
    "too.many.dots".)Could you clarify what you mean by: '...........cases like ".net".................'
    I had always assumed that an extension was an extension was an extension......
    I only program on windows............
    I normally use this in my code:
         Gets The Extension.
         @param     f     A File To get The Extension of
         @return     The Extension part of the FileName.
         public static String getExtension( File f )
              String fileName;
              int index;
              int L;
              if( f != null )
                   fileName = f.getName();
                   L = fileName.length();
                   index = fileName.lastIndexOf('.');
                   if( (index > 0) && (index < (L - 1)) )
                        return fileName.substring( index + 1 ).toLowerCase();
              return null;
         }and just assumed that if somone renamed a file as blah.exe.old they meant it, and that Windows only ever cares about the .old part.
    Am I missing something?
    Not that anyone would ever get to run my programs, being just a hobbyist, still I like to think I'm learning the right way...........

Maybe you are looking for

  • Unable to check mail on the main menu using the em...

    Hi,  I have a Nokia N86 and when you complete the basic setup, it asks you for your email. At the main page, under the application icons, I see "Yahoo Mail (0)". I geussed that it automatically checks for my email. I sent myself an email on my comput

  • Issue with payment terms

    Hi all, This is an urgent requirement. We need to change the payment terms from 21 NET to 28 NET for two purchase orders at the purchase order level. How can this be achieved ? Thanks

  • Problems with e-mail folders

    Hi, I hope someone can point me in the right direction here. We use windows 7 and Outlook 2010 at home. My other half has a Nokia 635 and I have an -iphone (supplied by work. ) We both have the same e-mail address at home  of the form << [email prote

  • A dynamic logic

    Hello friends, How can sort below weekdays meaningfully like Monday, Tuesday, Wednesday, Thursday, instaed. There must be a dynamic logic . This is the output in the ALV-Grid-Output. WD        Nr-Accidents Monday        1 Saturday      2 Tuesday     

  • Xcode fails to launch on Snow Leopard

    If I attempt to launch XCode from the dock (as a standard user), I simply get an error message (see end of his message). The same happens regardless of the way XCode is launched, ie, from Spotlight, from the Applications folder, from the Applications