Searching for a file in a  directory

Hai,
i am ooking for a code that searches a file( file name's first part is given for example results) in a directory. so search code is going to search a filename like results.csv in the directory.
any idea?

Have a look at the [File API|http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html]

Similar Messages

  • I want to Search for a file within a directory

    how can i access a directory and search for a folder name in that directory

    Hi,
    SQL> set serveroutput on
    SQL>
    SQL> Declare
      2     l_conn UTL_TCP.connection;
      3     l_list ftp.t_string_table;
      4  Begin
      5     DBMS_OUTPUT.disable;
      6 
      7     l_conn := ftp.login( '172.21.15.15'
      8                        , '21'
      9                        , 'test'
    10                        , 'test123' );
    11 
    12     ftp.list( p_conn => l_conn
    13             , p_dir  => ''
    14             , p_list => l_list );
    15 
    16     ftp.logout(l_conn);
    17 
    18     utl_tcp.close_all_connections;
    19 
    20     DBMS_OUTPUT.Enable;
    21 
    22     If l_list.Count > 0 Then
    23        For i IN 3 .. l_list.Last Loop
    24           DBMS_OUTPUT.put_line(Trim(substr(l_list(i),instr(l_list(i),' ',-1))));
    25        End Loop;
    26     End If;
    27  End;
    28  /
    files1
    files10
    files11
    files2
    files3
    files4
    files5
    files6
    files7
    files8
    files9
    PL/SQL procedure successfully completedhttp://www.oracle-base.com/articles/misc/FTPFromPLSQL.php
    http://www.oracle-base.com/dba/miscellaneous/ftp.pks
    http://www.oracle-base.com/dba/miscellaneous/ftp.pkb
    Or Chris Poole's XUTL_FTP package:
    http://www.chrispoole.co.uk/apps/xutlftp.htm
    or with DBMS_BACKUP_RESTORE
    SQL> -- How to Install
    SQL> -- .../RDBMS/ADMIN/dbmsbkrs.sql
    SQL> -- .../RDBMS/ADMIN/prvtbkrs.plb
    SQL> -- .../RDBMS/ADMIN/catproc.sql
    SQL>
    SQL> Set Serveroutput on;
    SQL> Create or replace directory DIR_TEMP as 'c:\temp';
    Directory created
    SQL> Create OR Replace Procedure list_directory(directory Varchar2) Is
      2     ns          Varchar2(1024);
      3     v_directory Varchar2(1024);
      4  Begin
      5     v_directory := directory;
      6     DBMS_BACKUP_RESTORE.SEARCHFILES( v_directory
      7                                    , ns );
      8     For each_file IN (SELECT fname_krbmsft As Name
      9                         FROM x$krbmsft) Loop
    10        DBMS_OUTPUT.PUT_LINE(each_file.Name);
    11     End Loop;
    12  End;
    13  /
    Procedure created
    SQL> begin
      2    list_directory('c:\temp');
      3  end;
      4  /
    C:\Temp\prvtbcnf.plb
    C:\Temp\something.txt
    PL/SQL procedure successfully completedRegards,
    Christian Balz

  • How to search for a file?

    Hi I am currently using the below code to detect a file automaticaly in a thumbdrive. So currently I have to state the path directory to detect the particular file. Is there a way to search for the file in the thumbdrive using Java?
    public class Detect {
    public static void main(String[] args)
    File f = new File("f:\\");
    while (! f.exists())
    try { Thread.sleep(500); }
    catch (InterruptedException e) {}
    System.out.println("drive inserted!");
    }

    You'll need to recursively search through a top directory and all its subdirectories for all files. Here is a link how to do this.
    http://www.javapractices.com/Topic68.cjp
    You can search for all drives A through Z for the file (using something like new File("F:") and catching the exception if not found (and dont do anything with the exception). But exclude C and D drive since they are usually hard drives and take forever to search through. Also, you may want to use File.separator instead of '/" or '\' in your code since windowsXP uses one while Unix uses the other and you would want your code to be able to run on either operating system.
    Are you building a web page with this? if so, it will not work since your search code would be running on the server and not on the client's machine. Even if you were able to run it on the client machine via his browser, you cant because of security reasons (end users dont want to give you access to thier drives). If its a web page, look into file upload html tag called <input type="file". This allows the end-user to navigate on his machine to where the file is and download it without you having to search for it.
    If you writing an application instead of a web page, I think there is an applet you can use that will do the same thing as <input type="file".
    Searching though a directory structure isn't good since it takes too long for users t wait.

  • Searching for a file in java

    What I am trying to do is not very uncommon. I want to open a file in it's default application (or at least in a common one.)
    Mainly I am currently thinking either HTML files or PDF's.
    What I was wondering is how to search for a file and get its directory path. For example I want to search for the file "Acrobat". In windows its directory is "C:\Program Files\Adobe\Acrobat 5.0\Acrobat\Acrobat.exe"
    But I know in MAC or Unix the path could be very different. Not only that, but what if they did not use the default installation directory. I just want to find the path of a file by invoking a search. Is there currently any way to do this?
    I know I can open a JFileChooser and make the user search and find the program they wish to run it in, but that certainly is not very user friendly. I'd rather the program just searched for the proper application(s) and then called the exec() method to run the file in the program.
    Any help is appreciated.

    java.io.File provides a listRoots() method that returns all file system roots. So for Windoze you'd get 'A:/', 'B:/' 'C:/' ... etc.
    Unix you'd get '/' and so on.
    Now you can use other File methods to recursively scan the roots.
    Here's some (untried) code to get you going that searches for all java.exe found on all roots.
    import java.io.File;
    import java.util.Arrays;
    import java.io.FilenameFilter;
    import java.util.List;
    import java.io.IOException;
    public class FindIt {
      public FindIt () {
        File[] roots = File.listRoots();
        List list = new ArrayList();
        for (int i = 0; i < roots.length; i++) {
          scan(roots,list,new FilenameFilter(){
    public boolean accept(File file, String name) {
    return new File(file,name).isDirectory() ||
    name.equals("java.exe");
    public static void scan(File path,
    List list,
    FilenameFilter filter) throws IOException {
    // Get filtered files in the current path
    File[] files = path.listFiles(filter);
    // Process each filtered entry
    for (int i = 0; i < files.length; i++) {
    // recurse if the entry is a directory
    if (files[i].isDirectory()) {
    scan(files[i],list,filter);
    else {
    // add the filtered file to the list
    list.add(files[i]);
    } // for
    } // scan
    public static void main(String[] args) {
    new FindIt();
    You will run into problems with some roots as they will be removeable media (cd's diskettes) or network drives (potentially huge number of dirs to scan). So I do not recommend that you search on all roots, but a subset.
    Dave

  • Search for a file regardless of OS

    Hi there,
    I want to search for a file regardless of which OS I am using. User can enter a filename like D:/abc/project/file.txt or just simply file.txt. I am required to handle path natively because if the user is using windows they will enter the windows style path and if they're using linux, they will enter it the linux style.
    for all of you who think that im asking you to do my assignment, i am not, its a very very small part of the huge project and if someone could help me on this. I can find the file in the current directory if only a filename is given, but if the whole path is given, my search fails
    thank you very much

    What you might be able to do is take the string that represents the filename and tokenize on both \ and /
    Then, iterate through the tokens and substitute either char for the File.pathSeparator character.
    String fname;
              StringTokenizer st = new StringTokenizer(s,"\\/");
              while (st.hasMoreTokens()) {
                   fname += st.nextToken() + File.pathSeparator;
    something like that (better to use a StringBuffer instead of += too)

  • Searching for (1) file

    I'm trying to do a spotlight search for certain files named "DSC0xxxx (1).JPG" that I want to delete. When I type "(1)" in the search field all files with the number 1 come up. It's as though the parenthesis are ignored.
    Is there something with parenthesis that makes them invisible.
    I have thousands of files with the (1). It would be nearly impossible to locate and delete them one by one.

    I came here with a similar issue. Many files with (xx) don't show up under xx search or (xx) search with OS 10.5.6. Not sure if Tiger was any different.
    From the advice of one of the folks in this thread (Francine Schwieder), I used "Raw Query" instead of "Kind" using the Finder search (not the Spotlight up in the corner). I assume this will work with msfind in the Terminal but haven't tried it.
    What I found so far...
    _kMDItemDisplayName == "("_ This finds the first item only *within the folder* that I'm searching. That is, once it finds one item, it seemed to stop(?!). It didn't find the next match, just the one.
    _kMDItemFSName == "("_ Finds all that match, unlike above. Very promising. All items with "(" are found whereas kMDItemDisplayName returned the only the first item in the searched directory. Don't know why.
    _kMDItemFSName == "(*B"_ This finds all matches, as above, if B is removed. But here, the letter B was within the last item in the directory. kMDItemDisplayName did not find this. Zero results. Nice that more than two wild-cards can be used!
    Message was edited by: kerferfer for a more beautiful formatting

  • I have 3 older ext. hard drives that I've utilized many times. Today while searching for old files, one of the three is no longer recognized by my PowerMac.  Any suggestions?

    I have 3 older ext. hard drives that I've utilized many times. Today while searching for old files, one of the three is no longer recognized by my PowerMac. The drive is not listed in Disk Utility.  Any suggestions?

    Is the computer in you equipment line:
    Dual Core Intel Xenon
    (which is not a PowerMac but a Mac Pro) the one you are asking about, or do you have an older PowerMac?
    If a Mac Pro, their forums are here:
    Mac Pro
    and, as Mac Pros have a totally different architecture from the pre-2005 Macs this forum covers, you may not have the same issues that can affect the older models. If someone didn't notice your equipment line, you could get advice that doesn't apply.
    If you really have a pre-2005 PowerMac, read on.
    If the stubborn external is USB and does not have its own power brick (i.e., it gets power only from the computer's UBS ports--"bus powered"), it may not be getting enough power. As electric motors age, they can demand more power than when new, and the power available on any USB port is limited.
    The typical workabouts to making a computer recognize an aging, bus-powered USB drive are:
    Get a powered USB hub (has its own power brick
    Get a "Y" USB cable: 1 Meter USB 2.0 A to 5 Pin Mini B Cable - Auxiliary USB "Y" Power Design for external hard drives.
    The second gets power from two USB ports on the computer and often that's enough.
    Remember that the USB ports on your keyboard seldom provide enough power even for a thumb drive, so be sure to use the USB ports on the back of the computer.

  • How Can I Search for Media files by Length?

    I want know how can I search for media files (mov, mp4, flv and movie files in general) by their length?
    If this search function is confirmed as definitely not possible on the OS, I would appreciate someone recommending app that might be able to perform such a search?
    Many thanks

    No possible way. Because the files may be enoded with differing codecs, compression, etc., you can only sort by file size, not the 'length' of the movie files.
    Clinton

  • How to get the file size (in bytes) for all files in a directory?

    How to get the file size (in bytes) for all files in a directory?
    The following code does not work. isFile() does NOT recognize files as files but only as directories. Why?
    Furthermore the size is not retrieved correctly.
    How do I have to code it otherwise? Is there a way of not converting f-to-string-to-File again but iterate over all file objects instead?
    Thank you
    Peter
    java.io.File f = new java.io.File("D:/todo/");
    files = f.list();
    for (int i = 0; i < files.length; i++) {
    System.out.println("fn=" + files);
    if (new File(files[i]).isFile())
         System.out.println("file[" + i + "]=" + files[i] + " size=" + (new File(files[i])).length() ); }

    pstein wrote:
    ...The following code does not work. Work?! It does not even compile! Please consider posting code in the form of an SSCCE in future.
    Here is an SSCCE.
    import java.io.File;
    class ListFiles {
        public static void main(String[] args) {
            java.io.File f = new java.io.File("/media/disk");
            // provides only the file names, not the path/name!
            //String[] files = f.list();
            File[] files = f.listFiles();
            for (int i = 0; i < files.length; i++) {
                System.out.println("fn=" + files);
    if (files[i].isFile()) {
    System.out.println(
    "file[" +
    i +
    "]=" +
    files[i] +
    " size=" +
    (files[i]).length() );
    }Edit 1:
    Also, in future, when posting code, code snippets, HTML/XML or input/output, please use the code tags to retain the indentation and formatting.   To do that, select the code and click the CODE button seen on the Plain Text tab of the message posting form.  It took me longer to clean up that code and turn it into an SSCCE, than it took to +solve the problem.+
    Edited by: AndrewThompson64 on Jul 21, 2009 8:47 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to search for a file and copy it to somewhere else in terminal

    So basically how can I search for a file on my computer named "testingtesting.txt" and copy it to my desktop using terminal? I have very little experience in terminal, so I was going to try and use the mdfind command, then store that output as a variable, and use that variable as the source for the cp command, but I feel like there is probably a much simpler method. So basically how could I find a file named "testingtesting.txt", copy it, and paste it to my desktop using terminal.

    Is there any particular reason that you must use Terminal?
    You could just download the free EasyFind from the App Store and find the file quickly. Do whatever you wish with it.
    Good luck,
    Clinton

  • 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]

  • Search for a file with part of a filename in a given folder.

    How can I search for a file with part of a filename in a given folder?
    Or can I change the columns in Advanced Search so that the heading is filename?

    thanks, Michel. it had occurred to me to put a scratch tag on the folder, but I was hoping for an easier way. in future I'll do as you suggest though, because it's easier than what I have been doing.
    daryl

  • Searching for a file

    Is there an easy way to modify how it works when you try and "find file".
    Now when I do a search for a file (let's say the file's name is "GREEN"), the OS finds hundreds of files where the word "Green" might be included.
    But what do I do if I just want the FILES named "GREEN" or "GREEN.01", etc... to be included?
    Thanks!

    Hello! Click on the "name" and "contains" boxes etc and a popup menu comes up allowing you to refine your search to name is et. Tom

  • Searching for a file in client backups - Window's Home Server 2011

    Here is my problem:
    I have great backups on WHS2011, but only need to restore a couple of files.  I am looking for a file a non-standard program uses, and it is not in any of the normal places.  I can restore the file if I can find it, but is there a way I can search
    for a file in these .DAT files?
    Many thanks.

    As this thread has been quiet for a while, we assume that the issue has been resolved. At this time, we will mark it as ‘Answered’ as the previous steps should be helpful for many similar scenarios.
     If the issue still persists and you want to return to this question, please reply this post directly so we will be notified to follow it up. You can also choose to unmark the answer as you wish.
     In addition, we’d love to hear your feedback about the solution. By sharing your experience you can help other community members facing similar problems.
     Thanks!
    Arnav Sharma | http://arnavsharma.net/ Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading
    the thread.

  • Searching for a file name?

    Hey Guys,
    Is there a way to fine the name of a text file? For example, I have 3 files 1235.txt, 2568.txt, and 2568.txt. I need to find one of these files and write user info into each one and then update the file with current user info.
    I was just wonder if there is anyway you could search for a file name?
    The reason I need to do this is because I want to store user details into seperate files, because I don't really want to use a random access file and using one file for all the users seems alot harder, when finding a file users info...
    Thanks Guys,
    The 31st Cook
    PS. I will post the code if required.... Thanks Again

    O yeah, I remember (google refresh my memory) this is what we were going to use in the first place except.. Because we must demo the program on completely locked down computers we can't install the drivers (that's what I was told) So, we can't use it...

Maybe you are looking for