Help on searching file in a directory ??????????????????

hi there
let's say i have a directory C:/myFolder and in the folder there are several files, i need to find if "test.txt" is in this folder. should i use File class to create an instance first like the following
File f = new File("C:/myFolder");
String[] fileList = f.list();
for (int i=0; i<fileList.lengh(); i++)
fileList.equal("test.txt")
//do something
and loop each item in the list to compare with "test.txt" to see if it is there or not, is there any other way to implement this?

You might want to refer to the API documentation for questions like that. It says:
"An abstract representation of file and directory pathnames."

Similar Messages

  • Search file within a directory

    hi there... i need to search for a file in a directory. but when i execute it, instead of just typing news.txt i need to type C:/news.txt why is that so when i already concat it.. here is the code and thank you in advance.
    public static void main(String[] args) throws IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
         System.out.println("Enter file to search : ");
    File filename = new File(in.readLine());
    if (filename.exists()){
         String b = ("C:/").concat(filename.getName());
    System.out.println("File name : " + b + " " +"found");
    else{
    Sender sm = new Sender();
              sm.doSend();
    }

    my problem is that when i run the program...i have to type C:/news.txt to search for the file...but this is not i want it to be i want to search by just typing news.txt..understand?? thank you

  • Searching file from directory located at http path.

    Hi All,
    I have made the program to search for a file in a directory and its subdirectories. This is working fine when my directory is located on local machine. But if the same directory is placed in HTTP path, the code fails to search a directory. Does anyone has idea how can i connect to site so as to access the directories. I used URL and URLConnection to read and write file to the site, and this is also working fine but when it comes to directories i find no solution. Please help.

    This works fine if i map http://flash/ on my C: and
    try to list files in directory C:\Mojo. Can you please
    tell how can i know whether the http server i am
    trying to access allows directory listing or not.
    Because if it does not i have administrator rights on
    the server and i can make the changes required.You can see if your Web server allows directory listing by simply
    typing in the URL you want to examine, inside your browser, and see if
    it shows you a directory listing. For instance, if you type in:
    http://flash/Mojo/
    in your browser's address bar, and you see a list of files in that
    directory, then your Web server supports directory listing.
    Note, though, that you can't use the File list() method to get a list of files.
    You'll have to make a connection, read the input stream, and then parse
    the filenames out of the HTML that the Web server returns. (You can see
    what the HTML looks like, by doing View Source inside your brower. That's
    what you'll get back from your Java program.)
    --Steve

  • Utility VI for searching for the occurance of a string in all files in a directory

    Is anyone aware of a utility VI that can search for a string(s) in all
    file types such as doc, xls, ppt etc in a specified directory?

    Greetings,
    I'm having an issue (using 8.5) with a directory read in. I've attached my elementary VI. Basically I want to read in mutliple files (they will be the same array size), and analyze each file. I am confident I will be able to analyze the data as necessary, I'm just having a problem parsing the data. Verbally I know exactly what I need to do just doesn't seem to be working in labview. Reading in the directory isn't the hard part, but breaking up the 2D data into the number of files I have apparently is for me. 
    1. Read in (user defined) directory
    2. List the file names | # of files in the directory
    3. Perform MAX value and % analysis of data on AMP array 
    Any help would be greatly appreciated. Even if it's just verbally pointing me in the right direction. I've attached the VI and 3 example data files I read in.
    Thanks in advance...I really feel like I should know this one, but I usually deal in individual files, this is my first directory read.
    Best Regards,
    Chazzzmd 
    Attachments:
    labview text upload.zip ‏33 KB

  • Help with utl_file (read/write file from local directory)

    Need help reading/writing file on local machine from plsql using 10.2 DB.
    I am trying to read/write a file from a local directory(laptop) without success.
    I have been able to read/write to the database server directory but can't write to directory on local machine.
    The utl_file_dir parm has been set to * and the db restarted but I can't get it to work... Here's the plsql statement.
    out_file := UTL_FILE.FOPEN ( 'C:\PLSQL', 'TEST.TXT', 'W' ,32767);
    Whenever I run it continues to write to c:\PLSQL dir on the database server. Have looked at the "Directory" object and created MY_DIR = C:\PLSQL but it writes to the db server.
    Running 10.2 on a remote windows server, running PLSQL using sql*navigator.
    Thanks in advance for your help..

    I don't see how you expect the server to be able to see your laptop across the network, hack into it and start writing files. Even if it could, what if there is more than one laptop with a C: drive? How would it know which one to write to?
    Is there a shared drive on the server you can access via the laptop?

  • [HELP] Search Files Function

    Hi,
    Could someone please help me fix this function below. It's suppost to search files in a dir for a particular string. I have files in the "./" dir but the function does not seem to output nothing at all.
    The search is also suppost to ignore the filez ending with .zip, .rar ect...
    public static void searchFiles(String s)
            File file = new File("./");
            String as[] = file.list();
            long l = 0L;
              label0:
            for(int i = 0; i < as.length;)
                if(as.endsWith(".zip") || as[i].endsWith(".rar") || as[i].endsWith(".gz") || as[i].endsWith(".jar") || as[i].endsWith(".7z"))
    continue;
    try
    long l1 = 0L;
    BufferedReader bufferedreader = new BufferedReader(new FileReader(as[i]));
    Object obj = null;
    do
    String s1;
    do
    if((s1 = bufferedreader.readLine()) == null)
    continue label0;
    l1++;
    } while(!s1.contains(s));
    l++;
    System.out.println((new StringBuilder()).append(" [").append(l).append("] ").append(as[i]).append(" (Line ").append(l1).append(") ").toString());
    System.out.println((new StringBuilder()).append(" ").append(s1).append(" ").toString());
    System.out.println("");
    } while(true);
    catch(IOException ioexception)
    System.out.println("Critical error while opening file for search!");
    ioexception.printStackTrace();
    i++;
    System.out.println("");
    System.out.println("");
    System.out.println((new StringBuilder()).append(" ").append(l).append(" results for ").append(s).append(".").toString());
    }Edited by: user13462345 on 12-Dec-2010 11:31                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    for(int i = 0; i < as.length;)This is an infinite loop, when as.length > 0
    If there is a file and this file doesn't require
    if(as.endsWith(".zip") || as[i].endsWith(".rar") || as[i].endsWith(".gz") || as[i].endsWith(".jar") || as[i].endsWith(".7z"))
    there will be no output.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Search through files in a directory

    How do I get a list of the files in a directory? I am aware of JFileChooser but it is not what I am looking. I need to search the contents of the xml files in the directory. I can do this with one file but need to do it with them all.

    // where files in subdirectory \files below the application directory
    File dir = new File(".\\files\\");
      if(dir.exists()){
        File[] list = dir.listFiles();
        for (int i = 0; i < list.length; i++){
          String fileName = list.toString();
    int iPtr = fileName.lastIndexOf("\\");
    int jPtr = fileName.indexOf(".xml",0);
    if (jPtr>-1) {
    String longName = fileName;
    String shortName = fileName.substring(iPtr + 1, jPtr);
    // file name in short name

  • Give a handmake function to search all files in the directory.

    To scan drive, folder, ets.
    I maked this, but my function is big bleep, a devil will break his legs here.
    Need small workable solution.
    Attachments:
    function.txt ‏7 KB

    Sergey,
    Here is an example file which looks through every file in a directory.http://zone.ni.com/devzone/cda/epd/p/id/2157
    It should save you some time if you are having issues with your code. 
    Regards,
    Kyle Mozdzyn
    Applications Engineering
    National Instruments
    Regards,
    Kyle M.
    Applications Engineering
    National Instruments

  • Ziping and unziping files in a directory Please help

    I have a program to zip files in a directory and create a .zip file.
    But am not able to unzip the file back to the orginal files. This file can be unziped using any unzip tool. But i want to unzip it using java itself
    thanks
    the code is as follows ......
    import java.util.zip.*;
    import java.io.*;
    public class Zipper
    private String dirname;
    public void compress_file(String input_dirname,String outfilename)
         //getting all the file names
         this.dirname=input_dirname;
         File f1=new File(dirname);
         String s[]=f1.list();
         try
              byte[] buf = new byte[4096]; //read buffer
              int retval; //return value
              FileOutputStream os = new FileOutputStream(outfilename);
              ZipOutputStream zos = new ZipOutputStream(os);
              FileInputStream is= new FileInputStream("File1");
              for(int i =0;i<s.length;i++)
                   System.out.println(s);
                   is = new FileInputStream("./conf/"+s[i]);
                   zos.putNextEntry(new ZipEntry("./conf/"+s[i]));
                   do
                        //read file in from input stream
                        retval = is.read(buf, 0, 4096);
                        //-1 indicates end of file
                        if (retval != -1)
                        //write buffer to output stream
                             zos.write(buf, 0, retval);
                   }while (retval != -1);
              //close this ZipEntry
              zos.closeEntry();
              //close input stream
              is.close();
              //close output stream
              zos.close();
         catch(Exception e)
              System.out.println("Exception occurred: " + e);
    public static void main(String[] argv)
         Zipper zp= new Zipper();
         zp.compress_file("./conf/","sample.zip");

    I'm kinda unclear about what problem you are having, but try this link
    http://developer.java.sun.com/developer/technicalArticles/Programming/PerfTuning/#Compression

  • Help.....problem with obtaining files from a directory

    Anaybody knows how to obtain list of files from a directory from j2me
    as in j2se ?

    I don't think it's possible because a MIDlet lives isolated from the rest of the device's filesystem. It can only store persistent data on the Record Media Store, which is unique for each MIDlet.

  • List all files in a directory on a server that hosts the applet

    Hei :)
    I have a problem. I want to list all files in a directory on my server. ( http://www.foo.bar/tw )
    The applet is in the root folder ( http://www.foo.bar ).
    So i tried it like this
    File fi = new URL(getCodeBase() + "/all/").getFile();But when I try to list the files, I get a SecurityException.
    Can anyone help me out?
    Peace!
    LoCal

    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=&qt=%2Blist+%2Bfile+%2Bserver

  • Name of the file in a directory

    There is a file in a directory say C:\abcd
    I want to find the name of the file in that directory.
    There is only one file in that directory
    How to proceed with this

    Sarma,
    That was a little abrupt and rude of you. Oracle_Friend was only asking if anyone knew of a way to detect the existence of a file in a directory, not exactly asking the world of us. And for all you know he probably has already searched in documentation, but probably isn't quite sure what to look for.
    Remember : The manual has every damn thing that you want. We can only help you when you are stuck somewhere after having treid many options.a) sometimes people don't know what options to try so how can they have tried many options before posting on here.
    b) The manual doesn't have every damn thing that you want. I want a lot of money and some lunch cos I'm getting hungry, but it doesn't have that. On a serious note though, the manuals do miss things and can't possibly cater for everybody's business requirements.
    Chill out man, and help rather than hinder.

  • HTML  Parsers and reading all files in a directory

    Hello all,
    I was wondering if there was a html parser included in java. I am writing a program where I want to be able to search all the files in a directory tree for a particular string. I was able to read one file in a single directory but not in any other directory. How would I go about writing code to be able to access all files in directory that has multiple sub folders.
    Also, when I started to write my program I tried to use the DOM XML Parser to parse my html page. My logic behind this decision was that if you look at html code it is an xml document. But as I was trying to run my program I noticed that I had to convert my html document into xml format. I really don't want to have to build my own html parser. Is there a html parser that is included in Java. Oh my program is just your basic text program. No interfaces.
    Thanks for any help that you can provide
    Hockeyfan

    a particular string. I was able to read one file in
    a single directory but not in any other directory.
    How would I go about writing code to be able to
    access all files in directory that has multiple sub
    folders.
    You can do that several ways.
    Most likely you'll end up with some sort of recursive iteration over the directory tree.
    Not hard to write, somewhat harder to prevent memory problems if you end up with a lot of data.
    Also, when I started to write my program I tried to
    use the DOM XML Parser to parse my html page. My
    logic behind this decision was that if you look at
    html code it is an xml document. But as I was
    trying to run my program I noticed that I had to
    convert my html document into xml format. I really
    don't want to have to build my own html parser. Is
    there a html parser that is included in Java. Oh my
    program is just your basic text program. No
    interfaces.
    A VALID xhtml document is a valid XML document.
    Problem is that most HTML isn't xhtml.
    Another problem is that most HTML is fundamentally broken even to its own standards (which have always been based on SGML on which XML is also based).
    Browsers take that into account by being extremely lax on standards compliance and effectively making up tags as they go along to fill in the missing ones in the trees they parse.
    That's however not a standardised process and each browser handles it differently (and as a result most html will render differently in different browsers).
    Java contains a simple HTML parser in Swing, but it's primitive and will only parse a subset of HTML 2.0.
    There are almost certainly 3rd party libraries out there that can do better, both free and/or commercial.

  • Search files which filename contains a speicific string

    Hi
    I'm lookng for a way to find all files in a directory which part of filename contains a specific string.
    e.g.:
    string = hello
    files;
    - 1hello2.txt
    - 22he45.txt
    - gehello42353.txt, ....
    The result should be either an index or the complete filename that matches. In the example I'd found index 0 and 2, or 1hello2.txt and gehello42353.txt.
    Actually I have the list of the files with the "recursive list.vi".
    Any suggestions are welcome.
    Thanks for your precious help
    Yves
    Solved!
    Go to Solution.

    You can use List Folder - function with *hello* -pattern.
    From there you get filenames, which include that specific pattern.
    If you allready have list of files:
    - use Scan string for tokens in a for loop and if token index != -1, then you can add that array index to the list.
    I´m sure there are better ways to do this, but nothing I can come up with quickly.
    Attachments:
    search.png ‏16 KB

  • Upload all the files in a directory

    Hi,
    I have searched in forum for a solution to my problem (Upload all the files contained in a certain directory) but all I've found is solutions to upload a single file using the bean JspSmartUpload. I had myself used this bean to uploads files to an server, but files choosed by the user with the <input type="file">. What I'm wanting know is different and I can't find a solution to it. I've tried to change the jspsmartupload to do this but I'm having no success..
    Anyone can help?
    Thanks in advance,
    Nuno.

    I don't believe there's any support in pure html forms to accomplish this.
    The File class has a listFiles() method, that will return an array of all the files in a directory. As this code must run on the client machine, you will need to write an applet to accomplish this. You will also have to worry about the security sandbox, and sign your applet.
    To get each file to the server you will need to create a URL object, openConnection on it, set up a multipart form POST to it, and transfer the files, one by one.

Maybe you are looking for

  • UPS and Surge Protection

    I just purchased a Mac Pro 3 gHz Tower and I would like to properly protect my tower as well as 30" mac cinema display, external harddrive, and cable modem line. If my power did go out, I would just need several minutes to save and close the machine.

  • HT2513 Ical sync with iPad limited to 2 years in the future

    Ical sync from Mac to iPad only appears to work for events up to 2 years in the future. After two years from current date no events show up on iPad. Can you increase this to sync events three years into the future?

  • My purchased TV shows are on Apple TV, but my purchased Movies and Music is not, what gives?

    My purchased TV shows are visible on Apple TV, but my purchased Movies and Music are not, what gives? From Apple TV menu, I used to click on "Computer" and choose my laptop and I could watch TV, Movies, Photos, Music, whatever.... but now the "Comput

  • DAILY EXCISE REGISTER REPORT

    Dear expert I am beginer in sap,and working on sap 2007b, i want a report for daily excise register which  formate is as (date   Op.Balance  PurchaseQty  jobworkQty   ProductionQty  Total    SaleQty JobWorkQty  ProductionQty Total   ClosingBal) Pleas

  • Business Object Data Services (BODI) without SAP MDM?

    Hi, From an architectural point of view; do you always have to use SAP MDM when you want to use the  Business Object Data Services (e.g. for data validity checks when creating customers)? Or can you use  Business Object Data Services in combination w