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

Similar Messages

  • File browse functionality for all files within a directory

    I have an app where you use file browse to select a file on the file system. Then, I parse the file name to determine other attribution to record in database, which may result in more user interaction before creating the database record.
    So, currently users can do this one file at a time. Anything available to let me loop through all files within a user-specified directory?
    Thanks,
    Steve

    I have an app where you use file browse to select a file on the file system. Then, I parse the file name to determine other attribution to record in database, which may result in more user interaction before creating the database record.
    So, currently users can do this one file at a time. Anything available to let me loop through all files within a user-specified directory?
    Thanks,
    Steve

  • 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

  • Searching files within folders

    Hi,
    lets say i have a directory in finder for example mac os>music>r&b albums>2008
    if i am in the r&b albums directory, if i type 'usher' in the top right search box, surely it would make sense to only search the directory i am in (r&b albums) and any sub directories within that (2008 folder for example), like windows explorer does? why does it do a system wide search? i can do that in spotlight if i wanted to.
    I only want to find the results in that folder and any sub folders contained within it. basically whatever folder i am in, i want that to be the ceiling folder, i dont want the search results to go beyond that. is this possible?
    bascially i want it to do the search like windows explorer does. and the first person that tells me that this is how macs work and if i dont like it go back to windows is gonna get a virtual punch in the face!
    thanks in advance for any help.

    I'm not sure I'm following you. Here is the results of selecting the Music folder in a Finder window. The second screenshot is the result of typing one letter in the search field of the first window. The thing I've done to produce the different screen is type "e" in the search field. I did not go back and highlight Music. You will note that the music folder in what is being searched.
    Maybe you can give a step by step of what your doing and what view option are you using.

  • 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."

  • Is it possible to select all files within a directory (and not the folders/subfolders)?

    For instance, in my iTunes directory, I would like to select all of the music files without selecting the other olders (artist name, album name). Going through with Shift+click and command+click will take an eternity. If I just highlight everything and hit "open", it will open ALL of the folders as well as opening the actual files. I want to skip the folders if possible with a mass selection.

    Well, its gonna be an expensive comparison since there is no non-arbitrary way to iterate through the files, but try:
    String f1, f2;  // the comparing files
    //get a primary list of files to iterate through
    Process p = Runtime.getRuntime.exec("ls");  // if in Linux
    BufferedReader pri =
        new BufferedReader(
        new InputStreamReader(
        p.getInputStream()));
    while((f1 = pri.readLine()) != null){    // for each file...
        Process q = Runtime.getRuntime.exec("ls");  // get all file names
        BufferedReader sec =
            new BufferedReader(
            new InputStreamReader(
            q.getInputStream()));
        while((f2 = sec.readLine()) != null){   // and for each of these
            if(!f1.equals(f2))  // as long as it's not the same file
                DO_COMPARISON(new File(f1), new File(f2));   // compare them
    }

  • When searching files within folders does not show all? Plz help

    This problem occured recently, few days back.
    When searching a name or extention it does now show all the files with the same name or extention?

    Figured it out I used straight serial cable. put null modem adapter solved the problem.

  • Trying to modify SaveDocsAsSVG to open and save all files within a directory automatically

    I am trying to do as the title suggests, but I can't find a way to specify the folder I want the script to look at and I can't get it to open/save/close the files without user interaction. Another way to say it is that I need this to be itterative as the PC I'm using cannot handle too many open files at once.
    On a side note, I can't even find the documentation. Example, what arguments does Folder.selectDialog() accept? Where is the documentation for that?
    Thank peeps!
    Using CS6 trying to convert EPS to SVG

    Here is what I have so far. I think I'm close I just need to figure out how to open the documents in the app and close them after converting them so only one document is open at a time. My goal is to run this program over night since there are thousands of files to convert. Thank you all for your help!
    app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
    try {
              if (app.documents.length > 0 ) {
                        // Get the folder to save the files into
            var inFolder = Folder( Folder.desktop + '/temp' )
            var files = inFolder.getFiles( /\.eps$/i );
                        var destFolder = null;
                        destFolder = '~/Desktop/temp';
                        if (destFolder != null) {
                                  var options, i, sourceDoc, targetFile;
                            // Get the SVG options to be used.
                                  options = this.getOptions();
                            // You can tune these by changing the code in the getOptions() function.
                                  for ( i = 0; i < files.length; i++ ) {
                      //THIS IS WHAT I NEED HELP WITH
                      var docRef = open(files[i]);
                      sourceDoc = app.documents[i]; // returns the document object
                                            // Get the file to save the document as svg into
                                            targetFile = this.getTargetFile(sourceDoc.name, '.svg', destFolder);
                                            // Save as SVG
                                            sourceDoc.exportFile(targetFile, ExportType.SVG, options);
                                            // Note: the doc.exportFile function for SVG is actually a Save As
                                            // operation rather than an Export, that is, the document's name
                                            // in Illustrator will change to the result of this call.
                                  alert( 'Documents saved as SVG' );
              else{
                        throw new Error('There are no document open!');
    catch(e) {
              alert( e.message, "Script Alert", true);
    /** Returns the options to be used for the generated files.
              @return ExportOptionsSVG object
    function getOptions()
              // Create the required options object
              var options = new ExportOptionsSVG();
              // See ExportOptionsSVG in the JavaScript Reference for available options
              // Set the options you want below:
              // For example, uncomment to set the compatibility of the generated svg to SVG Tiny 1.1
              // options.DTD = SVGDTDVersion.SVGTINY1_1;
              // For example, uncomment to embed raster images
              // options.embedRasterImages = true;
              return options;
    /** Returns the file to save or export the document into.
              @param docName the name of the document
              @param ext the extension the file extension to be applied
              @param destFolder the output folder
              @return File object
    function getTargetFile(docName, ext, destFolder) {
              var newName = "";
              // if name has no dot (and hence no extension),
              // just append the extension
              if (docName.indexOf('.') < 0) {
                        newName = docName + ext;
              } else {
                        var dot = docName.lastIndexOf('.');
                        newName += docName.substring(0, dot);
                        newName += ext;
              // Create the file object to save to
              var myFile = new File( destFolder + '/' + newName );
              // Preflight access rights
              if (myFile.open("w")) {
                        myFile.close();
              else {
                        throw new Error('Access is denied');
              return myFile;

  • Itunes 10.2.2 not importing all files within a directory

    Hello all, here is my very frustrating issue.
    I am running Itunes 10.2.2.14 on a x64bit Windows 7 machine and i am having an issue importing my full library from an external USB harddrive. Originally all the music on this external drive was at one point in time completely imported and functioning in iTunes. The short version of this long story is that I moved my main personal server from windows 7 to ubuntu, after installing VM player and attaching a external HD with my music iTunes will only import 7% of my music!! I have doubled checked permissions and this is not an issue. This is also not a format issue as the mass majority of my music is .mp3.
    I have cleared the music library several times, and even used another PC to import the folder and have found that iTunes appears to be importing the exact same 7% of my music library. The only article i have found that is even close to providing a explaination is page 4 on this discussion here:
    https://discussions.apple.com/thread/2566265?start=45&tstart=0
    Although this workaround appears to be for a Mac, is there any way to do this in Windows/Linux?
    I do not have this issue importing into Ubuntu Rythmbox. If this is really an issue of extended attributes where did they come from and why is iTunes rejecting the import with absolutely no message/errors?
    This is a major bug (to me) as i am currently unable to sync the mass majority of my music, much of which was purchased from Apple!?!?!
    Any help is greatly appreciated!!
    Thanks.

    UPDATE--> Manually adding folders (drag from explorer and drop on music libray) appears to be functioning as a work around. I have been testing individual folders and so far so good.
    While this may be a workaround i have HUNDREDS of folders! =(

  • Script to open all PST files in a directory and open with Outlook.

    Hi!  I am looking for a script that opens all PST files in a directory, opens it in outlook, and writes to a log to see if it completed correctly.  I'm new to VBscript and just want to see how the script would be written.
    Thank you!!

    Thank you for all the input!  JRV, I went through the repository and couldn't find anything about importing into Outlook.  I will use it for future references and I appreciate you directing me there.
    Grant, I need to be able to locate all PST files within a directory, not point it to a specific pst.  I also need it written to a log file.  Here is what I have...Don't laugh, I'm very new...
    const ForAppending = 8
    set objTextFile = objFSO.OpenTextFile ("C:\Users\jimmy.nguyen\Desktop\Lucky.txt", ForAppending, True)
    set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("WScript.Shell")
    strCommand = "C:\Program Files (x86)\Microsoft Office\Office12\outlook.exe"
    Set objExecObject = objShell.Exec(strCommand)
    wscript.sleep 4000
    Set myOlApp = CreateObject("Outlook.Application")
    Set myNS = myolapp.GetNamespace("MAPI")
    myNS.AddStore "objfile.name"
    Sub ShowSubFolders(fFolder)
    Set objFolder = objFSO.GetFolder(fFolder.Path)
    Set colFiles = objFolder.Files
    For Each objFile in colFiles
    If UCase(objFSO.GetExtensionName(objFile.name)) = "pst" Then
    objFile.Name
    End If
    Next
    For Each Subfolder in fFolder.SubFolders
    ShowSubFolders(Subfolder)
    Next
    End Sub
    strResults = ShowSubFolders(fFolder)
    objTextFile.WriteLine(strResults)
    objTextFile.Close

  • To pick files from multiple directory in FILE ADAPTER

    Hi all,
    Is their any settings or adapter configuration parameters to be used  to pick  the files from multiple directory .

    Hi,
    You can only specify one directory on the communication channel. The advance selection allows the selection of different files within this directory.
    Therefore you will need a communication channel for each directory you wish to pull files from.
    (Just looked at the blog and see it is possible after all - I'm on the wrong SP)
    Kind regards
    Colin.
    Message was edited by:
            Colin Bickell

  • Okay, i have 2 bugs with maverick.  First, when I delete a file within a window, the files deletes but the preview doesn't delete until I close the window and reopen it.  Second, I work on a network of computers and the search feature is now buggy...

    Okay, i have 2 bugs with maverick.  First, when I delete a file within a window, the files deletes but the preview doesn't delete until I close the window and reopen it.  Second, I work on a network of computers and the search feature is now buggy...  When I search for a file, A) it asks me if it's a name, or it wont produce anything, and B), its slower than in prior OS versions and in some instances I have to toggle to a different directory and go back to my original directory in the search: menu bar or the search wont produce anything...  Very buggy. 

    It appears to me that network file access is buggy in Maverick.
    In my case I have a USB Drive attached to airport extreme (new model) and when I open folders on that drive they all appear empty. If I right click and I select get info after a few minutes! I get a list of the content.
    It makes impossible navigate a directory tree.
    File access has been trashed in Maverick.
    They have improved (read broken) Finder. I need to manage a way to downgrade to Lion again.

  • Finding file within directory

    I'm currently using InDesign CS5.5
    I have an automation script I wrote for datamerge in javascript but I've had trouble finding any references to searching for files with javascript. I'm well aware you can't in javascript for the web but there is server side scripting but can't find where any tutorials are online.
    What im trying to acheive is this line here... but in javascript.
    var rootName = app.doScript('set theFile to (do shell script "ls /Path/To/Folder")', ScriptLanguage.APPLESCRIPT_LANGUAGE);
    now to explain why im using this incase anyone wants this or wants to know... this will give me a list of filenames in a directory..
    I then apply..
    var filename = rootName.split('.').reverse().slice(1).reverse().join('.');
    which strips everything but the name of  the file without the extension.
    Part of my program is.. each csv file that comes in will not have the same name so I use this to get the name and then later apply it to my datasource and for saving out the PDF.
    I'd appreciate if anyone can help me acheive looking for a file within javascript or if they could send me a link to where some documentation is.
    I have tried using getFiles("*.csv") but I get errors.. when I slap an alert after getting the file it shows the file with the entire path and I can't use slice because it doesn't do anything. literally it doesn't slice. This is why I was using applescript. I'm not sure if its more efficient or not to use Javascript for this or Applescript just would like to keep it all one language.
    Eventually I'd like to figure out how to set up a for function or some sort of count to grab only 1 file at a time in the case that 2 files make it to the directory.
    Also if anyone wants the code to do a datamerge and save out to pdf I'll gladly post.
    Thanks

    jtcdesigns1 wrote:
    I'm better at modifying than creating
    Modify this to taste
    filename = fetch_me_a_file ("*.csv");
    if (filename == null)
    alert ("No file found, or user canceled");
    else
    alert (filename);
    function fetch_me_a_file (mask)
    var fileList = Folder.myDocuments.getFiles(mask);
    if (fileList.length == 0)
      alert ("No files found");
      return null;
    if (fileList.length == 1)
      return fileList[0].name;
    var selectedFile = Folder.myDocuments.openDlg("Fetch me a file", mask);
    // Canceled?
    if (selectedFile == null)
      return null;
    return selectedFile.name;
    I was wondering if and how your Split Off Filename line worked, but decided to use this RegExp instead:
    name = filename.replace(/^.+\//, '');
    (replacing everything before and including the final forward slash with nothing) but then I thought, wait a minute. The 'object' returned by both getFiles and by openDlg is not actually a file name -- even though JS conveniently translates it to a fully qualified path when asked --, it's a file object. And a regular File object has this useful property 'name': that's just the file name.

  • Batch code for running a find/replace all on multiple files within a source floder/directory

    What I need is a Batch source code that will open all files in a folder/directory and run a find and replace_all query within them and then save all the files.  The files were created in Illustrator and saved using the Scene7 FXG format extension.    These files will be uploaded into Scene7 as a group after the find and replace macro/query is run on the code.  The same find and replace query will be the same for all the files.  Basically this function or batch process  will save time in setting the same parameters all at one time instead of having to set the parameters individually in scene7.
    a source code sample of the find/replace module macro might be              searchString:  s7:colorvalue="#FFFFFFFF" 
                                                                                                                          replaceString: s7:colorValue="#&txtclr;"
                                                                                                                          searchWhat   "FXG document"    
                                                                                                                             searchSource:  true,
                                                                                                                        useRegularExpressions:   true
    I have no problems creating batch files within Ai and PhotoShop but I have limited programming skills in how to create source code for manuipulating documents outside of those apps or in a OS invironment.
    I could probably come up witha simple program to do what i want for one document but i get lost when dealing with multiple documents in a source folder (prolbem is,  I will be dealing with thousands of documents not 100 or less)
    If anything which Adope cloud app would work best:  Dreamweaver or Edge code   (or just use my notepad)

    What I need is a Batch source code that will open all files in a folder/directory and run a find and replace_all query within them and then save all the files.  The files were created in Illustrator and saved using the Scene7 FXG format extension.    These files will be uploaded into Scene7 as a group after the find and replace macro/query is run on the code.  The same find and replace query will be the same for all the files.  Basically this function or batch process  will save time in setting the same parameters all at one time instead of having to set the parameters individually in scene7.
    a source code sample of the find/replace module macro might be              searchString:  s7:colorvalue="#FFFFFFFF" 
                                                                                                                          replaceString: s7:colorValue="#&txtclr;"
                                                                                                                          searchWhat   "FXG document"    
                                                                                                                             searchSource:  true,
                                                                                                                        useRegularExpressions:   true
    I have no problems creating batch files within Ai and PhotoShop but I have limited programming skills in how to create source code for manuipulating documents outside of those apps or in a OS invironment.
    I could probably come up witha simple program to do what i want for one document but i get lost when dealing with multiple documents in a source folder (prolbem is,  I will be dealing with thousands of documents not 100 or less)
    If anything which Adope cloud app would work best:  Dreamweaver or Edge code   (or just use my notepad)

  • 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

Maybe you are looking for

  • Upload of GL balances in mid year go live

    Hi gurus, appreciate if you can please tell me things to keep in mind and steps to upload balance sheet and p&l accounts in mid year go live in May and also client wants to see p&l from January in sap????????? waiting for your reply. THanks

  • Iphone backup / restoring!!

    Hi guys, wondering if someone could help. My Iphone and a few others are all backed up to the same itunes account. Is it possible for example, that if somebody else gets a new iphone device, they can restore my last backup (backup my iphone created)

  • Add Cost center description in FB01

    Hi All, I want to add new field in txn FB01 for item level. There is field Cost center in the Item level, i want to display description of the cost center. On second screen(300/310), we enter the cost center and after that if we hit save ,a new scree

  • How do i update preview on my macbookpro osx. i have updated the available update software but preview is'nt included in that

    How do i update the preview version 4.2 on my macbook pro osx which i bought 2.5 years ago. I need the newer preview version to use a scanner. i have updated all available software updates but preview was'nt one on offer

  • ITS 6.20 SP18 Problem with the top bar menus

    Hello Henning, we're using ITS 6.20 SP18 and experience a problem with the top bar menus in the SAPGUI for HTML (Enjoy Design) in both MSIE 6 and Moz Firefox 1.0.4. When clicking the dropdown menus in the top bar the menu simply won't open. This only