Replacing Characters in File

Ok, here is my situation. I am using a 3rd party application to upload files to my server. I am using another 3rd party application to index and search the files. The problem I am having is that the searching application will only recognize files without spaces in them, and most of the 3500 files that are going to be uploaded have spaces in them and I don't want to have to go through all of the files and rename them. What I am trying to do is to replace the space with an '_'. Here is the code that does the uploading.
<%
              Hashtable files = mrequest.getFiles();
                if ( (files != null) && (!files.isEmpty()) )
                    UploadFile file = (UploadFile) files.get("uploadfile");
     String filename = file.getFileName();
     pageContext.setAttribute("filename", filename);
                    // Uses the bean now to store specified by jsp:setProperty at the top.
                    upBean.store(mrequest, "uploadfile");
%>I know there is the replace(char,char) but I can't seem to get this to work. Any help would be greatly appreciated.

The replace commond itself is fairly simple
filename = filename.replace(' ', '_')
But you have to tell it to save the file using this new name.
is that what the pageContext setAttribute() call was for?
You might have to do
file.setFileName(filename);
Is this hashtable a table of all the files? Then you need to iterate through the map and update each entry.

Similar Messages

  • Find and replace characters in file names

    I need to transfer much of my user folder (home) to a non-mac computer. My problem is that I have become too used to the generous file name allowances on the Mac. Many of my files have characters such as "*" "!" "?" and "|". I know these are problems because they are often wild cards (except the pipe). Is there a way that I can do a find and replace for these characters?
    For example, search for all files with an "*" and replace the "*" in the file name with an "@" or a letter? I don't mind having to use the terminal for this (I suspect it will be easier).
    Is this possible? Does anyone have any suggestions?
    Thank you in advance for any help you may be able to provide.
      Mac OS X (10.4.8)  

    Yep.
    "A Better Finder Rename" is great for batch file renaming.
    http://www.versiontracker.com/dyn/moreinfo/macosx/11366
    Renamer4mac may be all you need.
    Best check out VersionTracker. In fact everybody should have this site bookmarked and visited daily.
    http://www.versiontracker.com/macosx/

  • BIG PROBLEM: CSS files not loading because of international characters in file name

    I have Muse Beta 7 in Spanish.
    The program creates a css file called master_a-página-maestra.css in css folder. It is referenced in the resulting HTML code here:
    <!-- CSS -->
      <link rel="stylesheet" type="text/css" href="css/site_global.css?3951792836"/>
      <link rel="stylesheet" type="text/css" href="css/master_a-p%c3%a1gina-maestra.css?fileVersionPlaceholder"/>
      <link rel="stylesheet" type="text/css" href="css/index.css?3948175564"/>
    When you work locally in your Windows formatted har drive, everything looks fine, but when you upload your files to a server, everything is screwed up. The server doesn't recognizes the URL and returns an error page, resulting in style errors in the entire site.
    This can also happens with html files if the title of the page contains international characters or with images if the image file name in your Hard Drive contains international characters.
    I already pointed out long time ago Muse was generating file names with international characters like á, ñ, etc but nobody cared about it. Too bad. I had to activate file name customization but I think that Muse should replace automatically this characters in the same way that it replaces other conflictive characters like commas or ampersands.
    This is not a fault of the FTP client. Accented characters are not web safe regardless of the FTP client you are using. It is a server side issue. Some servers support it some others don't. I don't mind if it works in Adobe Catalyst server because the final website is going to be in another server and maybe next year when paid hosting is ended the client may move it to another server.
    It makes more sense to replace accented characters in file names by their not accented equivalents ('a' instead of 'á', 'N' instead of 'Ñ', etc) and avoid all this problem.

    Zak, It is funny you mention it, because the site I am talking about is hosted in 1and1. try this: http://www.artofwalls.com/rosannawalls/biografía.html
    As you can see, the offending "í" in the file name causes 1and1 server to throw a "page not found" error. And this has happened with many other servers I have tried since.
    Muse boast of generating code fully compatible with all major web browsers but by using international characters in file names it ggenerates code suitable only for very few web servers. International characters have been always a no-no for internet URLs. Internet was designed by people who didn't care about ascii codes beyond 127 so using international characters in html file names is just call for problems.
    "to work with your hosting provider to determine how to enable Unicode encoded (UTF-8) file names and HTML files on their servers" is not a viable solution most of the time unless you are a Very Important Client of your host provider. If not, making changes means money for them and if you are the only one who complains, they are going to just tell you to not use international characters in your names.

  • Address book: Find and replace characters?

    Hi all,
    I just imported VCF file from Outlook to Address book. I am in Iceland and the Icelandic characters came wrong. Is there any way to batch find and replace characters in Address book? That is in individual cards.
    Thanks,
    Hilmar

    I believe the only way would be to write an AppleScript.

  • French Characters in File Names

    Hello,
    Despite my instance not use French and/or other special
    characters in files names, we have inherited a project (approx 2500
    topics) with French characters in the file name. When we generated
    the project and post it on an Apache server, the topics do not
    display as the server replaces the characters with symbols.
    RX5, during the generation process, replaced the French
    characters with underscores, RX 7.0.1 keeps the characters within
    the file name. In RX 7.0.1 is it possible to replace the characters
    with underscores during the generation process?
    Regards,

    If this is the other thread, then you did get a response, several in fact. It may not have been the answer you wanted but that's another matter.
    http://forums.adobe.com/message/129875#129875
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • Remove LF characters from file names

    I have a folder full of files with filenames that contain LF character (ASCII code 10).  I want to use Automator's "Replace Text" funcion to remove these non printing characters from file names.  Is there a way to do it?
    If automator is not able to do this task, I will take a bash script or applescript solution as well...

    Take a look at: http://stackoverflow.com/questions/4417588/sed-command-to-fix-filenames-in-a-dir ectory
    (I changed  tr -d "\r\n" to tr -d "\n", but try both)
    for f in ~/Desktop/*
    do
        new="$(printf %s "$f" | tr -d "\n")"
        if [ "$f" != "$new" ]; then
            mv "$f" "$new"
        fi
    done

  • WRITE CHARACTERS TO FILE???

    Hi everyone,
    I am working on a VI that has to write some characters into an existing
    file.
    I have used: Open File--> Write to File--> Close File but once it
    writes the desired data to that file it also writes some kind of bug
    which cannot be read once that File is read.
    Therefore I used the Wirte Characters to File SubVI which works ok.
    When the new data comes in it has to replace the old one, this means
    that the APPEND TO FILE option of the subVI is set to FALSE. The problem
    is that everytime my VI runs and generates the new data that will
    replace the old one, it asks me if I want to replace the existing file,
    which is what I want to do.
    My question is, if there is any way to override the prompt window that
    asks if the e
    xisting file will be replaced and perform the "replacement"
    automatically?
    Appreciate any help,
    Horacio Castilleja
    [email protected]

    This is a common problem with using some of the simple VIs that do not
    present all of the common/usefull functions.
    If you "Save As..." the Write Characters to File.vi to another name like "My
    Write Characters to File.vi" and add a boolean control
    to the front panel or boolean constant to the diagram and connect it to the
    "Advisory Dialog? (display:T)" boolean input of the Open/Create/Replace
    File.vi, with a False, it will suppress the dialog box.
    Stu
    Horacio Castilleja wrote in message
    news:[email protected]..
    > Hi everyone,
    >
    > I am working on a VI that has to write some characters into an existing
    > file.
    > I have used: Open File--> Write to File--> Close File but once it
    > writes the desired data to that file it also w
    rites some kind of bug
    > which cannot be read once that File is read.
    > Therefore I used the Wirte Characters to File SubVI which works ok.
    > When the new data comes in it has to replace the old one, this means
    > that the APPEND TO FILE option of the subVI is set to FALSE. The problem
    > is that everytime my VI runs and generates the new data that will
    > replace the old one, it asks me if I want to replace the existing file,
    > which is what I want to do.
    > My question is, if there is any way to override the prompt window that
    > asks if the existing file will be replaced and perform the "replacement"
    > automatically?
    >
    > Appreciate any help,
    >
    >
    > Horacio Castilleja
    > [email protected]
    >
    >
    >

  • Wild cards in Replace text in File names

    Hi all,
    Is there a way to use wildcards in the Automator action to replace text in file names.
    Thanks
    Ro

    No - the *Rename Finder Items* action does not accept variables or wildcard characters. You can use a *Run Shell Script* action if you are familiar with that kind of thing, and I have an action that will replace a substring that is delimited by the specified text or numerical index, if that would work (it is available here).

  • I had two files named graphics and I replaced one graphics file with another which was the wrong one.  Can I undo my replacement?  I move the wrong one, which was on my desktop into another one and that is when it as me if I wanted to replace the file.

    I accidently replaced a file with another.  Can I undo my action? 
    I had two files named graphics.  One was on my desktop and another was within another file called solitarie.  I move the one on my desktop (wrong file) into the solitarie file and was asked if I wanted to replace the graphics file in the solitarie folder (the correct one).  I said yes accidently and then remembered that I had made a mistake.  If I use undo, it only move the wrong file back to the desktop.  Is there an undo of replace?

    Sorry, but's that's why you get the warning. "Replace" means just that - the new file over-writes the old one. There is no undo.

  • How to transfer file from ipod touch to i tunes. i have files in my ipod , ut itunes is  new so its telling if u sync the ipod all the files will be replaced but no files in the itunes.. so kindly help me how to transfer the files  from i pod to itunesb

    how to transfer file from ipod touch to i tunes. i have files in my ipod , ut itunes is  new so its telling if u sync the ipod all the files will be replaced but no files in the itunes.. so kindly help me how to transfer the files  from i pod to itunes......

    Some of the information below has subsequently appeared in a document by turingtest2: Recovering your iTunes library from your iPod or iOS device - https://discussions.apple.com/docs/DOC-3991
    Your i-device was not designed for unique storage of your media. It is not a backup device and media transfer was designed for you maintaining a master copy of your media on a computer which is itself properly backed up against loss. Syncing is one way, computer to device, updating the device content to the content on the computer, not updating or restoring content on a computer. The exception is iTunes Store purchased content.
    iTunes Store: Transferring purchases from your iOS device or iPod to a computer - http://support.apple.com/kb/HT1848 - only media purchased from iTunes Store
    For transferring other items from an i-device to a computer you will have to use third party commercial software. Examples (check the web for others; this is not an exhaustive listing, nor do I have any idea if they are any good):
    - Senuti - http://www.fadingred.com/senuti/
    - Phoneview - http://www.ecamm.com/mac/phoneview/
    - MusicRescue - http://www.kennettnet.co.uk/products/musicrescue/
    - Sharepod (free) - http://download.cnet.com/SharePod/3000-2141_4-10794489.html?tag=mncol;2 - Windows
    - Snowfox/iMedia - http://www.mac-videoconverter.com/imedia-transfer-mac.html - Mac & PC
    - iexplorer (free) - http://www.macroplant.com/iexplorer/ - Mac&PC
    - Yamipod (free) - http://www.yamipod.com/main/modules/downloads/ - PC, Linux, Mac [Still updated for use on newer devices? No edits to site since 2010.]
    - 2010 Post by Zevoneer: iPod media recovery options - https://discussions.apple.com/message/11624224 - this is an older post and many of the links are also for old posts, so bear this in mind when reading them.
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive - https://discussions.apple.com/docs/DOC-3141 - dates from 2008 and some outdated information now.
    Copying Content from your iPod to your Computer - The Definitive Guide - http://www.ilounge.com/index.php/articles/comments/copying-music-from-ipod-to-co mputer/ - Information about use in disk mode pertains only to older model iPods.
    Get Your Music Off of Your iPod - http://howto.wired.com/wiki/Get_Your_Music_Off_of_Your_iPod - I am not sure but this may only work with some models and not newer Touch, iPhone, or iPad.
    Additional information here https://discussions.apple.com/message/18324797

  • File not found when using write characters to file

    OK, I am missing something really basic here.  Whenever I try to use the Write Characters to File function, if I try to give it a path beyond the C:\filename directory, it returns an error.  In other words, C:\Dan works, but C:\Dan\Test reurns an error. WHAT am I missing?

    Bingo! That is the problem. You have to make sure the directory exists before you attempt to write files to it.
         BTW: In LV there is a function for creating folders programatically. A good way to see if a directory exists is to attempt to list its
                   contents. If the list function returns an error, the directory doesn't exist and you have to create it.
    So make use of the error that the file write returns. If you get an error, start at the root of your path and test to see if each level exists, and if not create it. When you have all the folders in place repeat the file save.
    Mike...
    Message Edited by mikeporter on 05-24-2007 12:55 AM
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • When I delete com.apple.audio.SystemSettings.plist my audio/sound problems are solved. However when the file is replaced with another file, the sound is crappy and the quality is reduced. Can you please help me?

    When I delete com.apple.audio.SystemSettings.plist my audio/sound problems are solved. However when the file is replaced with another file, the sound is crappy and the quality is reduced. Can anyone please help me?
    Sincerely,
    Eric

    Run this when you have the problem and post the results here.
    EtreCheck
    This will tell us what is loaded

  • I downloaded CS6 Red Plug-In and added to Package Contents, replaced the current files with the new without backing up, now my RED footage thumbnails and color-correction don't WORK! How do I get my old importerRed file back!!?? HELP!

    I downloaded CS6 Red Plug-In and added to Package Contents, replaced the current files with the new without backing up, now my RED footage thumbnails and color-correction don't WORK! How do I get my old importerRed file back!!?? HELP!

    Try asking in the Premiere Pro  forum seems to be an Adobe Lab for Premiere Pro

  • How do I replace one video file with another

    Hey all
    I'm new to Imovie, so please bare over with me.
    I made a long movie using a MOD format file from my JVC home camera
    When I where to convert or burn the movie in Imovie it made an error.
    After much trouble I found out that it was the MOD format that was the problem
    So I bought an expensive piece of software that converted the MOD file to MOV:
    And with a new test project it now works flawless...
    Anyways back to the original project and the problem:
    - I have now converted the original MOD file to MOV
    - I have the original Imovie project with the MOD file.
    How do I replace the mod file in the imovie project with the new mov file, while keeping, that is transfering all my work on the mod file over to the new mov file?
    Thnx
    Kris

    • In the Layers Panel draw the Layer’s Vector Mask icon onto the trashcan-icon
    • move that Layer above the new Text Layer
    • invoke Create Clipping Mask (command-alt-G) from Layers Panel’s fly-out menu or alt-click on the line separating the two Layers’ icons

  • Mail.app hang if mail attachment have special characters in file name

    Hello,
    I have upgraded to 10.5.1 from last version of Tiger.
    After upgrade is not possible send message with attachment which have a czech special characters in file name (like á, í, é, ý, ú, ů, ě, š, č, ř, ž) with Mail.app. If I try it, CPU is overloaded and I must kill Mail.app process.
    The same problem have my friends who are running a clear installation of Leopard 10.5.1.
    Thanks for correction.

    I have the same problem with Hungarian chars. I tried out Tomas suggestion and it really worked. It is so dissaponting to have this kind of bug in a system like this. They never tested against this situation.
    I hope somebody at apple read this discussion and somehow this will be fixed in the near future.

Maybe you are looking for

  • Photoshop CS2 Fails to open

    Photoshop CS2 fails to open on two of our Macs. One is a G5 with Tiger, the other is a G4. I deleted the .psp file on the G5, tried to reopen, but it failed. Here is the error message. EXC_BAD_ACCESS (0x0001) Codes: KERN_INVALID_ADDRESS (0x0001) at 0

  • Pass a value in textbox from choose from list.

    Hi SAP experts, How to pass a value from a choosefrom list into textbox.? i'd created a form then in my one textbox, i inserted a choosefrom list. im trying to pass a CardCode but im getting a Bad Value ERROR. whis is my code in Creating a textbox wi

  • Why does it say invalid address when I try to update apps

    It keeps saying it's invalid, but it's not

  • Idvd won't start, missing file

    Used idvd without a problem, then later in the day idvd wouldn't start. Had to force quit and low and behold hidden under the idvd window was a message "unable to locate Billows01.dv I did a search for that file name to no avail. I did a reinstall fr

  • I moved a mach kernel and now I can't start OS X

    I remember moving a mach kernal last night. I didn't know what it was then, BUT I DO NOW! -My PB will not start up past the grey (w/ Apple) screen. -I have reinstalled the Os X CD -I have performed everything the support stuff says to do and nothing