How to search for files using wildcards * and ?.

Hi All,
I've been searching the forum for a couple of hours now and have been unable to find a good example of how to search a directory (Windows OS) for a file using wildcards * and/or ?. Does anyone out there have a good example that they can share with me?

Hi All,
First of all I want to thank everyone for taking the time to respond to my question. All of your responses where greatly appreciated.
I took the example code that was posted by rkconner, thanks rkconner, and modified it to allow me to search for files in a directory that contain * and/or ?. Yes, I said and/or! Meaning that you can use them both in the same file name, example: r??d*.t* would find readme.txt.
I've posed my complete and thoroughly document code below. I hope it is very helpful to other as I have searched many forums and spent many hours today trying to resolve this problem.
* File Name:
* Date: Jan 9, 2004
* This class will search all files in a directory using the
* asterisk (*) and/or question mark (?) as wildcards which may be
* used together in the same file name.  A File [] is returned containing
* an array of all files found that match the wildcard specifications.
* Command line example:
* c:\>java WildcardSearch c:\windows s??t*.ini
* New sWild: s.{1}.{1}t.*.ini
* system.ini
* Command line break down: Java Program = java WildcardSearch
*                          Search Directory (arg[0]) = C:\Windows
*                          Files To Search (arg[1]) = s??t*.ini
* Note:  Some commands will not work from the command line for arg[1]
*        such as *.*, however, this will work if you if it is passed
*        within Java (hard coded)
* @author kmportner
public class WildcardSearch
     private static String sWild = "";
      * @param args - arg[0] = directory to search, arg[1] = wildcard name
     public static void main(String[] args)
          String sExtDir = args[0]; // directory to search
          sWild = args[1];   // wild card to use - example: s??t*.ini
          sWild = replaceWildcards(sWild);
          System.out.println("New sWild: " + sWild);
          File fileDir = new File(sExtDir);
          File[] arrFile = fileDir.listFiles(new FilenameFilter()
               public boolean accept(File dir, String name)
                    return (name.toLowerCase().matches(sWild));
          for (int i = 0; i < arrFile.length; ++i)
     }     // end main
     * Checks for * and ? in the wildcard variable and replaces them correct
     * pattern characters.
     * @param wild - Wildcard name containing * and ?
     * @return - String containing modified wildcard name
     private static String replaceWildcards(String wild)
          StringBuffer buffer = new StringBuffer();
          char [] chars = wild.toCharArray();
          for (int i = 0; i < chars.length; ++i)
               if (chars[i] == '*')
               else if (chars[i] == '?')
          return buffer.toString();
     }     // end replaceWildcards method
}     // end class

Similar Messages

  • Please answer. how to search for files

    We need an integration with SAP. They send us files in the format: yyyymmddhhmiss.atv
    For example we receive following files:
    So, we dont know how to search for all files with extensions ".atv" in the directory.
    We are using PLSQL. Is there some way to resolve with UTL_FILE?
    Any other suggestion?

    A possibility:
    In sqlplus, issue a HOST command to list the files to a file:
    ls *.atv &gt; atv_dir.txt
    Then use utl_file to read atv_dir.txt and parse it for the file names.
    You could put the filenames in a pl/sql table and use that as loop control.

  • How to search for file in jsp page

    i need help on how to search for a file in a folder where there is a lot of how u search in a document in windows. i need a complete codes in jsp page.
    thank you in advance.
    Message was edited by:

    no i need to do a search engine in jsp page which is the j2ee.
    i type smth than tat file from any folder will appear the same way when u need to search your file in a document in windows.
    well can u nice people tell me where i can get the codes bcos i stinks when it come to programming.
    thank you very very very much.

  • How to search for brackets in wildcards?

    Is there any way to search for ALL characters (including punctuation, dashes, and spaces) that are within brackets [ ], including the brackets? For example, after wildcard searching, I would like ALL of  [test1123 abc 7.77]  or [aaa 3_1 abc 7.77] to be highlighted (including the brackets) so that I could make them as conditional text.
    What is the proper wildcard search string that I should enter? Thanks.

    There is no simple, one-shot solution from within FrameMaker. The Wildcard option does not give you a full-fledged regular expression search engine, although that would be nice. The official explanation of wildcard character options is here: .html
    One thing could be more precise in the docs: * is for one or more word characters, like | stands for one or more non-word characters.
    To achieve your goal I would suggest to do as follows:
    To find all one-word instances, search for \[*\] - you have to use \[ for each literal [ because the brackerts are special characters as soon as the Wildcard option is selected
    To find two-word instances, search for \[*|*\], etc.
    - Michael

  • How to search for files everywhere?

    When I use Apple-F to find files, apparently only some folders are searched, even when I have "This Mac" selected. For example, I cannot seem to find anything in ~/Library. Can I force it to search all folders that I have permission to view? Thanks for any help!

    to search those folders you need to include system files in your search.
    After you enter command+f to bring up a search window, click on "Kind" and scroll to "other". You'll get a popup window will all possible search parameters. Choose "system files" and set it to "include". To see even more items, select "Spotlight items" and include those.

  • How to search for file in a directory or subdirectories?

    I need ur help urgently. I'm currently doing a java project in which the program should be able to do file searching.
    For eg. if I key in a.jpg, it should display C:\pictures\a.jpg (a.jpg is stored in a folder called "pictures")
    But the problem is that my program is only able to search in the C drive only.
    If I move the file into a folder in the C drive, my program cannot detect this.
    Can you help me to solve this problem? I'm really looking forward for your reply.
    Thanks. Here are the codes.
    import java.awt.*;
    class FindFile
         public static void main(String args[]) throws IOException
              //reads the user input
              BufferedReader userInput;
                        userInput = new BufferedReader(new InputStreamReader(;
                        String s = userInput.readLine();
                        //quits the system               
                        //if user does not key in anything, prompt msg appear
                        else if(s.equals(""))
                             System.out.println("Command Syntax: java ListFiles <filename>");
                             System.out.println("<filename> - The full name of a file and extension (i.e., test.txt)");
                        else if(userInput != null)
                             String t = "c:";
                             File f = new File(t);
                             String[] files = f.list();
                             char[] qwet;
                             boolean test = false;
                             //check for the file name and compare with the user input
                             for (int i = 0; i < files.length; i++)
                                       System.out.println("File Found");
                                       System.out.print("The File Found at This Path: ");
                                       //display the path
                                       test = true;
                             //if file does not exist
                             if(test == false)
                                  System.out.println("File Not Found");

    well, i think the best solution would be make a recursive search through the directory tree. I don't know if you are familiar to this, but the functions that searches for the file would look like this:
    public String searchFile(String name) {
      File[] roots = File.listRoots();   // List all file roots (in windows the different units, c:, d:, etc.)
      for (int i = 0 ; i < roots.length() ; i++) {
        String aux = recursiveSearch(roots, name);
    if (aux != null) {   // If the "recursiveSearch" returns something different than null is that the file is founded, so we return the path.
    return aux;
    return null; // If we get there nothing has been found
    private String recursiveSearch(File f, String name) {   // f is the directory to search for the file with name "name"
    File[] childs = f.listFiles();
    for (int i = 0 ;i < childs.length ; i++) {
    if (childs[i].isDirectory()) {  // If that is a directory we search inside
    String aux = recursiveSearch(childs[i], name);
    if (aux != null) {   // We have found it inside this directory
    return aux;
    } else {  // Is a regular file
    if (name.compareTo(childs[i].getName()) == 0) {   // If the file is what we want we return his path
    return childs[i].getCanonicalPath();
    // If we get here is because the file is not inside the directory or any subdirectory on it
    return null;
    You should just call the function searchFile(name) with the name of the file you want to search. If it finds one with this name it will return his absolute path, and if he doesn't the desired file he will return null.
    If you don't understand anything just ask.
    (Note: i have not tested this code, so can be some mistakes, but it think it is almost correct. mmmhh don't now why, but [ & ] appear in my code as < & >. Just replace them.).
    Hope that helps.

  • How to search for folders using jsp ( or any other way)?

    Hey All,
    It's my first time writing here and i hope i can get some help ... i have created a payroll system using java and jsp techniques and mysql as the database, i want to create a backup page that will let the use to choose the destination folder for the back up, the backup is basically a mysqldump command that will get the destination folder as an argument and create the sql file there. the problem is i couldn't find anyway to let the user browse his local machine and choose the folder , which in returns return the folder path to be used in mysqldump....
    I know that html have <input type=file> but it's used for selecting file not folder...
    can someone come up with a solution for me coz it's urgent and i have to finish the project by the end of this week.,.

    Also you can use an OUTPUT clause ( need to modify your DML operations)
    create table itest ( i int identity not null primary key, j int not null unique )
    create table #new ( i int not null, j int not null)
    insert into itest (j)
    output inserted.i, inserted.j into #new
    select o.object_id from sys.objects as o
    select * from #new
    drop table #new, itest;
    The example below shows code that uses OUTPUT clause in UPDATE and DELETE statements to insert rows into an audit table.
    create table t ( i int not null );
    create table t_audit ( old_i int not null, new_i int null );
    insert into t (i) values( 1 );
    insert into t (i) values( 2 );
    update t
       set i  = i + 1
    output deleted.i, inserted.i into t_audit
     where i = 1;
    delete from t
    output deleted.i, NULL into t_audit
     where i = 2;
    select * from t;
    select * from t_audit;
    drop table t, t_audit;
    Best Regards,Uri Dimant SQL Server MVP,
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to search for file within compressed file

    I hope i can explain this correctly, I apologize in advance.
    What is the command to search for a file that may/may not exist within another compressed file?
    Situation is that I have a cron job that compresses the files in a folder on a scheduled date. I now need to search for a file that may exists in one of the several compressed files, which was a result of the cron job.
    Thanks in advance

    There's an open source utility called zgrep. You can probably get it from .
    Roger S.

  • How to import .MOD files using log and trasfer

    I am trying to get some footage taken on my Cannon FS20 into final cut pro
    When i mount the camera and go into the SD_VIDEO directory, each clip has 2 files, a .MOD and a .MOI
    When I drag these clips into the log and transfer window i get the error
    "filename.MOD contains unsupported media or has an invalid directory structure. please chose a folder whose directory structure matches supported media"
    How can i fix this?

  • How can I search for files in System and Library folders

    This arrose when I tried to find Archive Neither a Finder search or Spotlight found it, apparently because it is in Hard Drive/System/Library/CoreServices and the System folder is not searched. I've had similar problems when trying to find things in Library. How can I search these folders?

    You can enable the Finder to include System files in its search
    In a Finder finder window select Kind then Other… locate System files in the list and click the checkbox.

  • Searching for instances using getIntancesByFilter and ClientProcessService

    I am trying to get an array of all instances in a process so I can get some the data and use it to populate some dropdowns. I am using a custom, AJAX-enabled JSF presentation to call a server-side-no method in my component model. My code looks like this:
    Fuego.Papi.Instance[] things;
    Fuego.Papi.ClientProcessService cps = new Fuego.Papi.ClientProcessService();
    Fuego.Papi.InstanceFilter filter = new Fuego.Papi.InstanceFilter();
    filter.searchScope = SearchScope(ParticipantScope.ALL, StatusScope.ALL);
    filter.addAttributeTo("projVar", Comparison.IS, "projValue");
    things = cps.getInstancesByFilter(filter);
    foreach (thing in things){
         logMessage("Thing - " + thing.activityName + ".", "INFO");
    I think the code is failing at line filter.create(cps), but I can't be sure. When I launch the screenflow, I am presented with an error about invalid arguments for method signature [nameOfMethod]. I can't debug the method either because of this error.
    If I remove everything south of cps.connect();, I can loop through the project vars defined in the process. I am using a ClientProcessService because I want to use the existing session from the workspace to get this data. Any thoughts?

    I think you're just missing the processId in your logic ("/OrderEntry" in the logic below). Your use of "projValue" won't work unless you're looking for the hard coded string "projValue".
    // Create objects used by the filter that searches the engine
    ClientBusinessProcess cbp;
    InstanceFilter instF;
    // Connect to the process that is currently running.
    // In this example, the process name is "Order Entry"
    // (no space characters).
    cbp.connectTo(processId : "/OrderEntry");
    // create the filter
    instF.create(processService : cbp.processService);
    // filter based on instances done by ALL participants in any
    //   activity between the Begin and End activities
    instF.searchScope = SearchScope(participantScope : ParticipantScope.ALL, statusScope : StatusScope.ONLY_INPROCESS);
    // Get the orders with a order status of "Rejected"
    instF.addAttributeTo("projjVar", Comparison.IS, "Rejected");
    . . .Dan
    orderCount = length (getInstancesByFilter(cbp, instF))
    return orderCount

  • How to search for material without Inforecord and Contract

    Dear Experts,
    I am suppose to find out all the materials in the system, which does not have any Inforecord or any contract created. Since there are millions of entries, Can you please suggest some quick way to find this?
    Thanks and Regards,

    Dear Mash,
    I am suppose to find out all the materials in the system, which does not have any Inforecord or any contract created. Since there are millions of entries, Can you please suggest some quick way to find this?
    Step 1: Find out  how many material your plant having
                 Se16,  Table: MARC, only give the plant as  input and execute you will get all the material  for the plant , save it  to Xl sheet
    Step 2:  se16, Table: EINA
    Give the all material that in xl sheet as input and execute , you will get the all info record which are maintain for those material,
    now do some xl sheet stuff or Vlookup  those material which are not come in EINA table are the material for which  Info record is not maintain

  • How can I search for files with more than one keyword?

    I´ve created some keywords, and some files in my folder are tagged with two, three or more keywords.
    Is there a way to search for files using more than one keyword on the search field?

    Use the Find command (menu Edit) and in criteria at the right side is a plus sign to add another criteria and set it to your custom wishes.
    make a choice in results and you should be OK

  • Hi. I am using the iPhone 4S and when I'm searching for places using Google it does not automatically detect my location. How do I change this?  FYI...under settings i

    Hi. I am using the iPhone 4S and when I'm searching for places using Google it does not automatically detect my location. How do I change this?  FYI...under settings i

    If you are missing using google maps - try the Nokia map app called "here"

  • Hi. I am using the iPhone 4S and when I'm searching for places using Google it does not automatically detect my location. How do I change this? FYI...under settings i have it set at "Use new precise locations from my device."

    Hi. I am using the iPhone 4S and when I'm searching for places using Google it does not automatically detect my location. How do I change this? FYI...under settings i have it set at "Use new precise locations from my device."

    If you are missing using google maps - try the Nokia map app called "here"

Maybe you are looking for