Check for Correct File Name Syntax

What is the most efficient way to check if a String can be used as a file name? Here is my current (bulky) way:
public static boolean isValidFileName(String s) {
     try {
          File file = new File(s);
          file.mkdir();
          file.delete();
          return true;
     catch (Exception e) {
          return false;
Thanks!

Sorry about the poor code format, above. This is my first posting experience here.
public static boolean isValidFileName(String s) {
     try {
          File file = new File(s);
          file.mkdir();
          file.delete();
          return true;
     catch (Exception e) {
          return false;
}

Similar Messages

  • Need script to check for duplicate file names when copying a folder

    Hello,
    I am a new applescript user trying to write what I believe should be a simple script. I was planning on using the "add-new item alert" script as a template.
    Basically I have people copying folders of photos into a library folder, but I don't want the Finder to copy the photo if it already exists in the library. The images in the library are organized into subfolders.
    I need a script that will check all the file names in the new folder against all the file names in the library, and NOT add the new one if it already exists.
    If anyone can help it would be greatly appreciated,
    Thanks,
    C

    I have a script that "kind of" works. The only problem I've seen is that it gets confused when filenames contain characters that are fine in Macland but not good in Unixland. Forward slashes are a good example of this.
    In this case I have a folder in my home named "copytest" Inside copytest are two folders:
    Source (containing the images to be added)
    Dest (My existing library of images)
    It also assumes that the folder of images to be added contains no sub-folders. Hope this helps.
    tell application "Finder"
    set theSource to folder "source" of folder "copytest" of home
    set imagesToBeCopied to name of every file of theSource
    end tell
    repeat with theFile in imagesToBeCopied
    try
    if (do shell script "find -r ~/copytest/dest -name " & quoted form of (theFile as string)) is not equal to "" then
    --The file exists. Don't copy it
    else
    --the file doesn't already exist. Copy it.
    end if
    on error
    return "Failed while trying to check for existence of a file"
    end try
    end repeat

  • How do I find correct file name for Terminal?

    I am using the example code: sudo dd if=/path/to/downloaded.img of=/dev/rdiskN bs=1m with Terminal. The file is ubuntu.dmg but it claims "no such file or directory." How do I find the correct file name?

    If possible, drag the dmg into the Terminal window instead of typing out its path.
    (67069)

  • HT4972 I am trying to update ipod touch from ios 4.3.2 to ios 6.1.3.  I have it connected to my computer, and the summary in itunes indicates the update is available.  However, when I click "update", it opens Windows Explorer and waits for a file name to

    I am trying to update ipod touch from ios 4.3.2 to ios 6.1.3.  I have it connected to my computer, and the summary in itunes indicates the update is available.  However, when I click "update", it opens Windows Explorer and waits for a file name to open.

    I am not at that computer now, but I did check via windows update & with the check updates menu choice in the itunes program  - neither indicated a newer version of itunes is available. (it is a vista computer).
    The itunes software on the computer displays my ipod & the current ios (4.3.2), and indicates a newer ios is available (6.1.3). When I choose "update", I am taken to Windows Exploer and prompted to choose a file to open. it is as if the "update" button has the incorrect code attached to it.
    The ipod is working, but there are several app I would like to install, but I can't with the current ooperating system.

  • Variable subsitution for target file names

    Hi All,
    I am using variable subsitution for dynamic file names. I am using the multimapping for multiple files in the target.So i coluld not able to use the dynamic configuration for file names. Now i want to replace all the spaces in the filename to underscore.
    For example
    My payload filed value "file name in the target file".
    Now my filename  "file_name_in_the_target_file".
    How to achieve this using Variable subsitution.
    Regards,
    Ramalakshmi.G

    Use replaceString Function.
    file name
    Constant (" ")               --> replaceString -------> TargetField
    Constant ("_")
    Regards
    Ramesh

  • Framemaker uses $filename for short file name, can we edit this to change appearance? We do not want the short file name of long filename to include the .fm extension can this be removed or modified to make this happen?

    Framemaker uses <$filename> for short file name, can we edit this to change appearance? We do not want the short file name of long filename to include the .fm extension can this be removed or modified to make this happen? In compiling our books it would be helpful to not have this extension appear as it then requires us to create extra files without them.

    See: System Variables

  • Can't get Firefox to load at all after trying fixes from support web site. Have checked for lock file, processes running, reboot, reinstall. NO JOY.

    I'm running Vista for operating system on an HP laptop that's about 2 years old. I've installed all current updates.
    I've always used Firefox. It started crashing and creating processes but not launching. Went to support and scoped it out -- there was a lock file my profile directory. I deleted it, and Firefox started loading.
    Used it a few times -- closed the app each time on exist as per suggestions on support site info. One time -- back to square one, wouldn't load, just created a process. Reboot, ending process, checking for lock file, reinstalling -- all unsucessful.

    Brian
    Below is from using a SIP build.  It does offer G722, but it's way down on the list so it's never used...
    m=audio 32678 RTP/AVP 0 8 18 102 9 116 101
    a=rtpmap:0 PCMU/8000
    a=rtpmap:8 PCMA/8000
    a=rtpmap:18 G729/8000
    a=fmtp:18 annexb=no
    a=rtpmap:102 L16/16000
    a=rtpmap:9 G722/8000
    a=rtpmap:116 iLBC/8000
    a=fmtp:116 mode=20
    a=rtpmap:101 telephone-event/8000
    Taking Sreekanth's suggestion to try a Skinny build, I get the following when I make a call.  It offers codecs in the order I SET THEM AND ONLY THE CODECS I SET!  YAY!
    m=audio 19374 RTP/AVP 9 0 101
    a=rtpmap:9 G722/8000
    a=fmtp:9 bitrate=64
    a=rtpmap:0 PCMU/8000
    a=rtpmap:101 telephone-event/8000
    Using a Skinny build on the phones also solved other issues.  The phones use G711 when the whole path supports G711 and G722 when the whole path supports G722.  It doesn't always use G722 and rely on transcoding for the call paths that can't use it.  It's fantastic..  The phones also receive the QoS tagging that I set and that seems to result in better audio quality than on the SIP builds, which never did get those settings.  Finally, it even solved a slow Exchange 2013 answer issue I have been experiencing for quite some time.  I practically fell out of my chair when I saw everything that was fixed just by switching...
    Cisco, PLEASE FIX YOUR SIP BUILDS!  It's insane how the SCCP builds work perfectly and the SIP builds don't, especially with how much these phones cost..  I was thinking of possibly acquiring some 9951s, which are SIP only.  I'm a little leery about that at this point.  If they have the same kinds of issues as the SIP builds for the 7975g, there's no SCCP alternative to use..
    Sreekanth
    Thank you for suggesting a Skinny build..  That was about the only thing I didn't try.  I am happy beyond belief that this is working so well now, even though the SIP builds should be just as well developed as the SCCP ones.

  • I'm trying to "open"-get to a site--Ichoose Firefox as application; the next screen is another appication and asks for a file name. What do I do? I never get any further.

    I'm trying to get to "www.enoriver.org." A window appears asking me to choose an application--I choose Firefox. Then another window opens titled "Another Application" and asks for a file name at the botto0m of page. I choose Firefox from the list of files, paste it into the bar, hit "enter"--nothing happens. What do I do?

    Hi Leo! If you can stop these down load managers, you will be my hero.
    Dokie!!
    PS I have tried my best to warn members here on the forum, but I haven't got a lot of support so far.
    I have my figers crossed that the new team will get-er-done

  • When I send out mail from MS Outlook enterprise account in the office to my Mac at home they are received as "winmail.dat" files.  Even if I perform a "save as" to the correct file name the file format is still not recognized.  Why is this happening!?

    When I send out mail from MS Outlook enterprise account in the office to my Mac at home they are received as "winmail.dat" files.  Even if I perform a "save as" to the correct file name the file format is still not recognized.  Why is this happening!?

    http://www.joshjacob.com/mac-development/tnef.php

  • Sender file adapter - Can I use *.xml for the file name

    Hi Gurus,
    I have some interfaces where I need to pick the file from a directory. The name of the file will have Data<i>time stamp</i> as the naming convention. Can I use *.xml to pick up my files from this directory?
    The help.sap.com documentation says that we can use this naming convention.
    <b>
    &#9679;      File Name
    Specify the name of the file that you want to process. The name can contain placeholders (*, ? (placeholders for exactly one character)) so that you can select a list of files for processing.
    </b>
    I tried using *.xml for my file name in the communication channel, XI is not picking up this file.
    Please let me know if you have the solution.
    Thanks
    Kalyan

    Murthy,
    Thanks for the reply.
    I am using GuildFTP tool as my FTP server. In this tool, all the permissions were given for the file to pick up.
    The status of the file is good.
    Where in the file adapter configuration I have to select 'Read-only'?
    The file adapter is working perfect with the exact name of the file.
    Thanks
    Kalyan

  • File Handling (Check for existing file)

    now my problems is that i need to have a code that upon a request checks for a file (in the home dir) and if the file exists reads the information and ouputs it. here is an example:
    check if file TEST.DATA exists?
    check approved TEST.DATA exists
    information outputed...
    if the file is missing i need to have an error message...
    PS. sorry if the question falls under "lame" but i am fairly new to java and i dont know the commands that well... thank you in advance!

    File.exists()
    Reading Text from a File
    Useful places to seek for information:
    - Java API documentation
    - The Java Tutorial
    - Code examples from Java developpers Almanac
    - Google
    - ...

  • When I open up an e-mail attachment a box pops up PRINT TO FILE below that line OUTPUT FILE NAME with an empty line for the file name vs. simply going to my default printer?

    when I open up an e-mail attachment a box pops up PRINT TO FILE below that line OUTPUT FILE NAME with an empty line for the file name vs. simply going to my default printer?

    Make sure that '''''Print to File''''' isn't selected in the native print dialog box ''(see screenshot below)'' middle-right, and make sure your Printer is selected at the top of that dialog box.
    ''I'm a little confused why an email attachment would need to go directly to the printer, but that's what you asked about.''

  • How can i search for multiple file names (images) in bridge?

    Hello everyone!
    Does anyone know how to search for multiple file names in bridge?
    That is to copy & paste something like this: _MG_2152, _MG_2177, _MG_2194, _MG_2195, _MG_2202, _MG_2212, _MG_2219, _MG_2261, _MG_2362, _MG_2401
    Not using several criterias in the search box that is. That takes too long.
    Thanks
    Steffen Rikenberg Photographer
    Oslo, Norway.
    www.steffenrikenberg.no

    Try this add-on [https://addons.mozilla.org/it/firefox/addon/find-all/ Find All]

  • How to programmatically disable prompts for output file names in Acrobat X

    My code to programmatically disable output file names (below) is not working on a Windows 7 64-bit machine using Acrobat Distiller X.  It works perfectly on a Windows XP machine with Acrobat Distiller 8.
    The latest API Reference I was able to find is dated June 2008.  My logic follows this convention.
    I have confirmed that the registry key is updated as specified below.  I have also confirmed that I am able to write to the directory indicated.
    Please provide any suggestions to resolve. 
    Thank You!
    ~Lori
    'Create the Registry Key where Acrobat looks for a file name
            CreateNewRegistryKey HKEY_CURRENT_USER, _
                         "Software\Adobe\Acrobat Distiller\PrinterJobControl"
    'Put the output filename (FilePath) where Acrobat could find it
            SetRegistryValue HKEY_CURRENT_USER, _
                     "Software\Adobe\Acrobat Distiller\PrinterJobControl", _
                     C:\Program Files (x86)\Microsoft Office\Office12\MSACCESS.EXE, _
                     T:\PDF Files\Current Week\NFS_Lori,Test.pdf

    I remember seeing that the problem is thunking. A little more specifically, because it's a 32-bit driver but a 64-bit executable, there's a 32-bit system spooler process which will always show up as the EXE name.

  • Ask for the file name when printing on XP x64

    I have just installed my CS3 on Windows XP x64. Installation was successful and all is working fine. But there are few things which are working differently and I can not find any way to fix it.
    One of the problems I have is that I can not have it so that I will be asked for the name of the PDF file created. It simply goes through and allocates name of the file used for printing. It happens for all applications i.e. Word, Excel, InDesign, Corel. In my automatic processes I realy need to be prompted for the file name / location. Is it possible to modify some settings to have it under XP x64 ??? I hope it is.
    Thanks for advise.
    Tony

    I would like to add few details which may help to find the source of the problem.
    When I will select Adobe PDF as a printer, then click on Properties and select
    Prompt for Adobe PDF filename
    in Adobe PDF Output Folder then printing starts and will not progress at all. If I will change the Adobe PDF Output Folder to local it prints OK but is not asking for the file name / destination.
    How I can have it printing and asking for the file name / destination ? Or maybe on XP x64 it is not possible at all ?
    Regards,
    Tony

Maybe you are looking for

  • Slow transfer of video from my mac to my Apple TV

    Hi there! I have a Time capsule (bought last year) as wifi source and an Apple tv 2nd generation. When I try to copy video on my tv from my macbook air 1.7 GHz core i7 using airplay, the video on the tv starts and stops all the time, while it continu

  • Create pdf using Adobe acrobat sdk

    Hello, I'm new to this concept of using adobe sdk to convert a html into pdf.I would like to know few details regarding this.. I went thorugh the documentation but I did not get any help about the vector image support in the pdf and I aslo want to kn

  • Mail sent thru background job doesnt have all pages in attachment

    Hi Experts, We developed a program where the output is triggered by calling a smart form. We schedule a background job and we updated the mail address in Spool list recipent. After succesfull execution of job we checked the spool it is around 30 page

  • Web Service Client - SOAP/jms: Specific response queue (not default queue)?

    Hi @ll I try to define a specific jms response queue for a web service client that communicates SOAP/jms, running on a WLS 9.2. The web service itself runs also on a WLS 9.2 where also the request and response queues are located. By default the clien

  • MacBook crashes when connected to charger

    Hey, Recently my MacBook has been crashing when I put it on charge and doesn't respond when I restart the MacBook when I press the power button, its the Mid 2010 one bought it last October and its running OSX Lion..? Any ideas would be welcome, Thank