Best way to browse and read data from a lot of files?

Hi All,
I am trying to read tags from music files. Currently I'm listing all the files and then reading through the tags, as below:
List<File> result = new ArrayList<File>();
FilenameFilter mp3filter = new FilenameFilter() {
     public boolean accept(File dir, String name) {
          return name.endsWith(".mp3");
FilenameFilter wmafilter = new FilenameFilter() {
     public boolean accept(File dir, String name) {
          return name.endsWith(".wma");
FileFilter dirFilter = new FileFilter() {
     public boolean accept(File file) {
          return file.isDirectory();
File[] dirList = aStartingDir.listFiles(dirFilter);
File[] mp3files = aStartingDir.listFiles(mp3filter);
File[] wmafiles = aStartingDir.listFiles(wmafilter);
List<File> filesDirs = Arrays.asList(dirList);
List<File> filesMp3 = Arrays.asList(mp3files);
List<File> filesWma = Arrays.asList(wmafiles);
for (File file : filesMp3) {
     result.add(file);
for (File file : filesWma) {
     result.add(file);
for (File file : filesDirs) {
     List<File> deeperList = getFileListing(file);
     result.addAll(deeperList);
}and then read the files in a for loop through the list.
Is there a better way to do the same?

Well, you could optimize that just a little bit by only calling listFiles once with a filter that would accept directories, wmas, and mp3s all in one go. Then you could iterate through the results and separate them into the three categories after you had the complete recursive directory listing. That may be faster. But your OS will likely cache the results of the directory listing, thus minimizing the effort of your current approach. But honestly, no... you need the headers from every file, so you'll need to find each file and then check the headers.
If you want, you can cache the results somewhere for future reference. Are you concerned about performance or some such?

Similar Messages

  • Best way to control and read data from multiple instruments?

    Hello,
    I'm building an application to test power supplies involving multiple pieces of equipment over a couple of different comm busses. The application will also send control instructions to some of the instruments, and read data from some of the instruments. The reading and control profiles will not run on the same schedule (variable length control steps, configurable read interval).
    I was thinking of using a queued statemachine (producer/consumer) for the control profile and another to read the data, but I got concerned that there would be collisions between sending control commands and read commands to the same machine. Is there a suggested design pattern for implementing something like this?
    Timing of the commands isn't critical down to the milisecond, but I need to collect reasonably accurate timestamps when the data is read. The same is true for the control commands.
    Here are the instruments I'm going to use, if the are control, read, or both, and the communication method
    Instrument Funtions Comm Method
    Power Supply Read data Communicates to PMBus Adapter
    PMBus to USB Adapter Read data USB (Non-Visa)
    Switch control relays USB (VISA)
    Power Dist. Unit read data/control outlets SNMP (Ethernet)
    Electronic Load read data/control load GPIB (VISA)
    Thermal Chamber read data/control temp Ethernet (VISA)
    Thanks,
    Simon

    Hello, there is a template in LV called "Continuous measurement and Logging".
    It can give you some idea how to properly decouple the "GUI Event handler" top loop (where your Event structure is) from the DAQ and other loops.
    You do not need to totally replicate the above example, but you can find there nice tricks which can help you at certain points.
    The second loop from the top is the "UI message loop". It handles the commands coming from the top loop, and regarding to the local state machine and other possible conditions and states, it can command the other loops below.
    During normal run, the different instrument loops just do the data reading, but if you send a control command from the top loop to a certain instrument loop (use a separate Queue for every instrument loops), that loop will Dequeue the control command, execute it, and goes back to data reading mode (in data reading mode the loop Dequeu itself with a "data read" command automatically). In this way the control and data read modes happen in serial not in parallel which you want to avoid (but I think some instrument drivers can even handle parallel access, it will not happen in really parallel...).
    In every instrument loop when you read a value, attach a TimeStamp to it, and send this timestamp/value couple to the DataLogging loop via a Queue. You can use a cluster including 3 items: Source(instrument)/timestamp/value. All the instrument loops can use the same "Data logging" Queue. In the Datalogging while loop, after Dequeue-ing, you can Unbundle the cluster and save the timestamp and data-value into the required channel (different channel for every instrument) of a TDMS file.
    (Important: NEVER use 2 Event structures in the same top level "main" VI!)

  • Can you suggest a best way to store and read arabic from oracle database?

    Hi ,
    can you suggest a best way to store and read arabic from oracle database?
    My oracle database is Oracle Database 10g Release 10.1.0.5.0 - 64bit Production on unix HP-UX ia64.
    NLS_NCHAR_CHARACTERSET AL16UTF16
    NLS_LANGUAGE AMERICAN
    NLS_TERRITORY AMERICA
    NLS_CHARACTERSET WE8ISO8859P1
    I have presently stored the data in nvarchar2 field. But i am not able to display it correctly.

    Using the national characterset should work but there are other factors that you have to consider when working with NCHAR/NVARCHAR2/NCLOB.
    If possible, changing the characterset is usually the best solution if it's a possiblity for you.
    For more info:
    Dear Gurus: Can u pls explain the difference between VARCHAR2 & NVARCHAR2??

  • Best way to export and import data from an iPhone app?

    How do people here prefer to export and import data from an iPhone app?
    For example, suppose your app creates or modifies a plist. It might be nice to provide that plist to the user for separate backup and later allow them to re-import it.
    How do people do that? Email the plist to an address? If so, how would one later get it back in?
    Is there a common way people do this kind of thing?
    Thanks,
    doug

    Or maybe the best approach for this is some sort of file synchronization feature? Is there a way of having files from the app's filesystem automatically get stored on the computer's filesystem when synchronizing and vice-versa?
    doug

  • What is the best way to load and convert data from a flat file?

    Hi,
    I want to load data from a flat file, convert dates, numbers and some fields with custom logic (e.g. 0,1 into N,Y) to the correct format.
    The rows where all to_number, to_date and custom conversions succeed should go into table STG_OK. If some conversion fails (due to an illegal format in the flat file), those rows (where the conversion raises some exception) should go into table STG_ERR.
    What is the best and easiest way to archive this?
    Thanks,
    Carsten.

    Hi,
    thanks for your answers so far!
    I gave them a thought and came up with two different alternatives:
    Alternative 1
    I load the data from the flat file into a staging table using sqlldr. I convert the data to the target format using sqlldr expressions.
    The columns of the staging table have the target format (date, number).
    The rows that cannot be loaded go into a bad file. I manually load the data from the bad file (without any conversion) into the error table.
    Alternative 2
    The columns of the staging table are all of type varchar2 regardless of the target format.
    I define data rules for all columns that require a later conversion.
    I load the data from the flat file into the staging table using external table or sqlldr without any data conversion.
    The rows that cannot be loaded go automatically into the error table.
    When I read the data from the staging table, I can safely convert it since it is already checked by the rules.
    What I dislike in alternative 1 is that I manually have to create a second file and a second mapping (ok, I can automate this using OMB*Plus).
    Further, I would prefer using expressions in the mapping for converting the data.
    What I dislike in alternative 2 is that I have to create a data rule and a conversion expression and then keep the data rule and the conversion expression in sync (in case of changes of the file format).
    I also would prefer to have the data in the staging table in the target format. Well, I might load it into a second staging table with columns having the target format. But that's another mapping and a lot of i/o.
    As far as I know I need the data quality option for using data rules, is that true?
    Is there another alternative without any of these drawbacks?
    Otherwise I think I will go for alternative 1.
    Thanks,
    Carsten.

  • What is the Best way To Copy and paste data from 1 book to another

     I have 18 sheets in 5 different books that I want to extract data from specific cells.  What is the best way to do this?  Example:  1 sheet is called Numbers E-O1 data in 13:WXYZ. The data updates and moves up 1 row every time I enter
    a new number. So let's say I enter the number 12. Through a lot of calculations the output goes in 13:WXYZ. To what I call a counter which is a 4 digit number.  Anyways, how can I send that 4 digit number to a totally different sheet?  To bullet
    what I'm talking about
    data in cells Row 13:WXYZ in book called Numbers sheet E-O1
    send data to book called "Vortex Numbers" Sheet E-O row 2001:CDEF
    What formula or Macro can I use to make this work?
    thank you!

    Hello Larbec,
    Syntax:
    '[BookName]SheetName'!Range
    Enter in cell  2001:CDEF:
    ='[Numbers]E-O1'!13:WXYZ
    This assumes that the file is open in Excel. Otherwise you need to add the path:
    'ThePath[BookName]SheetName'!Range
    Best regards George

  • How do I prevent browsing and search data from being forwarded to Google by Mozilla, while still using Mozilla's Firefox as my default browser?

    I do enjoy using Mozilla's Firefox as my default browser, BUT, I don't enjoy the details of my life, to include my Internet activity, to be archived by Google, or anyone else, via Mozilla's/Firefox's sharing of my Internet browsing and/or search engine activity with any aspect or facet of the Google organization. With all of this said, my question is, "How do I prevent browsing and search data from being forwarded to Google by Mozilla, while still using Mozilla's Firefox as my default browser?"

    Firefox's default behavior includes no automatic interaction with Google.
    We do use Google as default search engine and to report web forgery in the 'help' menu, but no data are sent to Google without your knowledge, and you can change your preferred search engine at will.
    However many websites themselves make use of Google Ads which do cause interaction with Google when you load the webpages. This is visible in status bar and happens in any browser. The [https://addons.mozilla.org/en-US/firefox/addon/noscript NoScript] add-on for Firefox can largely save you from this problem.
    If you see things happening otherwise, please reply with details on what you see.

  • Static lookup lists:read data from a Java *.properties file

    Hi
    i need to make static lookup lists i am using read data from a Java *.properties file
    i am using the Class "PropertyFileBasedLookupViewObjectImpl" that wrote by Steve Muench in ToyStore.
    but i need to use the default language for that i update the loadDataFromPropertiesFile()
    method to find the correct properties file
    String temp=Locale.getDefault().getLanguage();
    String propertyFile =
    getViewDef().getFullName().replace('.', '/')+"_"+temp+ ".properties";
    the problem:
    For English(TEST_en.properties) it is good and working
    For Arabic(TEST_ar.properties) read from correct file _ar.properties
    but the dispaly character is wrong
    When Debug
    In the File 1=&#1583;&#1605;&#1588;&#1602;
    In debug 1=/u32423

    Depending on your use case you can either use a programmatic VO or directly expose the JV class as a data control.
    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_36/jdtut_11r2_36.html

  • Uploading Excel File and Reading Data from that File

    <b>Hi
    Can anyone Please tell me how to upload an Excel File in to the Web Dynpro Application and After that i want to read the data from that uploaded excel file in the Web Dynpro Application to the Web Dynpro table.
    Plz help me to solve this.......
    Regards
    Chandran</b>

    Hi,
    Upload Excel file using File Upload UI
    1)Add jxl jar folder in the lib folder of ur project.
    2)Go to properties of ur project and add jar to ur project.
    3)Using the File upload ui ,browse and upload the file.
    4)Write the read file in to ur server location using fileoutput stream.
    5)then using code u can read the excelfile from the server location itself.
    Here is the code:
         IWDAttributeInfo attInfo =wdContext.getNodeInfo().getAttribute("upload");
    /** get the name of excel file and storing it in the server with the same name and extention****/
    binaryType=IWDModifiableBinaryTypeattInfo.getModifiableSimpleType();
    fileuploaded = binaryType.getFileName();
    byte b[] = wdContext.currentContextElement().getUpload();
    File filename =new File("
    <Server name>
    <folde name>
    " + fileuploaded);
    try {
    FileOutputStream out = new FileOutputStream(filename);
    out.write(b);
    out.close();
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    /**Readind from the server**/
    int iRows = 0;
    try {     Workbook wb = null;
         Sheet sheet = null;
         wb = Workbook.getWorkbook(filename);
         sheet = wb.getSheet(0);
         int iColumns = sheet.getColumns();
          iRows = sheet.getRows();
         int i = 0;
        //get Cell contents by (COLUMN, ROW);
        for (int r = 0; r < iRows; r++) {
       for (int c = 0; c < iColumns; c++) {
         Cell cell = sheet.getCell(c, r);
         characterarray<i> = cell.getContents();
    //wdComponentAPI.getMessageManager().reportSuccess("Row"r characterarray<i>);
    i++;
    wb.close();
    Declare Globally
    //@@begin others
    String fileuploaded;
    IWDModifiableBinaryType binaryType;
    String characterarray[] = new String[1000];
    //@@end
    Also look at this blog too  /people/perumal.kanthan/blog/2005/03/21/reading-excel-data-from-java-using-hssf-api
    Thanks and Regards,
    Arun

  • Best Method for Importing and Exporting Data to a local 'resrouce'  file

    I've searched the forum, and seen glimmers of hope to what I am trying to piece together - but not in a concise way that will sink into my brain.
    Using Javascript on a PC for IDCS2, I'm writing a simple script that has a user interface.
    I'd like to have 4 default values for the user interface to be read from (and if altered, written to) a text file.
    What's the simplest way to go about this? I've read through many posts, and toyed around with readln and writeln functions, but nothing is working out. For some reason, I can't send any information to any file - let alone read it back in.
    Could somebody point me in the right direction? For simplicity sake let's say I have just one variable, "myVariable" - and I want to send it to and read it from c:\test.txt.
    Someday - this will all sink in. Right now, I'm reaching for Aspirin.

    Hi D Scott Chinn,
    Try something like this:
    var myFile = File.saveDialog ("Save file as:")
    if(myFile != undefined){
    var myString = "Write this string to a file."
    myFile.open("w");
    myFile.write(myString);
    myFile.close();
    Thanks,
    Ole

  • The best way to move 2TB of data from Win to Mac

    Hello,
    what is the best way me to move 2TB (multiple files) data from windows to Mac?
    I think that over the LAN, even using crossover cable connecting 1GB NICs would be painfully long. (Windows disk is quite fragmented)
    If I put windows (ntfs partitioned) disc to one of Mac Pro bays, will Mac allows me to access the date on it?
    if I take the disk of the windows PC and put it to [eSATA Hard Drive docking solution|http://eshop.macsales.com/item/Newer%20Technology/FWU2ES2HDK>, will Mac be able to mount it and let me copy the files from the windows disk?
    Any other ways of moving 2TB data from windows to Mac?

    Being able to read, also means, being able to mount said drive volumes.
    Windows 7 64-bit (Pro version if you have dual processor, which at this time really isn't needed that much) would work fine too.
    There are programs, some or most have their own limitations, allow Windows to read and write to Mac HFS+ file system volumes; or the reverse and allow Mac OS to read/write NTFS. None are what I call perfect.
    Becuase of limitations in older file systems and partitioning, Apple and Microsoft have implemented support for volumes larger than 2TB with GPT to replace aging Master Boot Record (Windows 7 even can't run off MBR with volumes larger than 1.9TB). Mac Pro uses GPT and can boot from very large volumes.
    eSATA docking stations. Depends on the interface and controller card if any, whether using SATA PCIe for one thing (you would not ever want to use USB though maybe USB3 PCIe if you can find one), therefore, use internal drive bays. Also, more concern with the drive temperature in one, they can get very warm in my experience.
    But maybe you do, maybe you don't, actually need to move data, maybe just have it read-only accessible.
    Putting the drive in a FW800 case would probably make the most sense, both now and for further use for booting (backup clones are handy and allowed) or for backup with Mac TimeMachine.
    But I would install Windows 7 on your Mac Pro. I use GPT for data drives in Windows and to read from in Mac OS environment.

  • What is the best way to import and export footage from the 5D Mark II?

    Hello,
    I've just finished shooting what I am considering to be my directorial masterpiece.  Shot it on the Canon 5D (1080p, 24fps), and the footage looks amazing.  Now I am ready to start editing and have been using premiere lately, but I have yet to figure out the proper pipeline.  I want to know the best way to retain resolution before I delve into this project.
    My questions:
    1)  What is the best way to start a new project and import the footage without having to render whilst editing, so as to retain all resolution and originality of the source footage?
    2)  What is the best way/ codec/ format to export this same footage once editing is complete so as to retain that crisp 1080p for which the 5D is so recognized?
    3)  What is the best way/ codec/ format to import and export/ render between premiere and after effects?  I am speaking mostly of vfx and color correction.  I also have some 30fps footage that I intend to slow down in AE and then import into premiere.
    I know this is pretty broad, but as a solo filmmaker I really need someone's guidance.  I rarely ever finish my films with the same, crisp look as the footage.  I need pipeline help, and really appreciate it!

    ascreenwriter wrote:
    Hello,
    I've just finished shooting what I am considering to be my directorial masterpiece.  Shot it on the Canon 5D (1080p, 24fps), and the footage looks amazing.  Now I am ready to start editing and have been using premiere lately, but I have yet to figure out the proper pipeline.  I want to know the best way to retain resolution before I delve into this project.
    My questions:
    1)  What is the best way to start a new project and import the footage without having to render whilst editing, so as to retain all resolution and originality of the source footage?
    2)  What is the best way/ codec/ format to export this same footage once editing is complete so as to retain that crisp 1080p for which the 5D is so recognized?
    3)  What is the best way/ codec/ format to import and export/ render between premiere and after effects?  I am speaking mostly of vfx and color correction.  I also have some 30fps footage that I intend to slow down in AE and then import into premiere.
    I know this is pretty broad, but as a solo filmmaker I really need someone's guidance.  I rarely ever finish my films with the same, crisp look as the footage.  I need pipeline help, and really appreciate it!
    1. Follow the advice above. Also use the Media Browser to import the footage in case you have spanned media files. Import files with the Media Browser.
    2. It largely depends on what you wish to ouput to: Blu-ray, web, etc. This FAQ gives the best answer: What are the best export settings?
    3. Use the Replace with Adobe After Effects Composition function.

  • Writing and reading data from a form

    I am trying to write a save and load feature for an application using mostly Jtextboxes and things. Basically I have a form that the user enters data into. I want to be able to save this data and load this data. I am relatively new to working on a GUI and I'm not quite sure if my knowledge of I/O applies to this. This is my stab at it but if I am completely off I would not be surprised. I don't want to print it to the command line but this was all I could think of right now. Any help would be greatly appreciated.     
    private void SavePrefs() {
              File SavePrefs;
              // get filename:
              fc.setDialogTitle("Select Filename For Site Data");
              int result = fc.showOpenDialog(f);
              if (result == JOptionPane.OK_OPTION) {
                   SavePrefs = fc.getSelectedFile();
                   // default file extension ".CMM"
                   if (!SavePrefs.getName().endsWith(".CMM")) {
                        // filename does not meet requirmeents:
                        System.out.println("NO CMIMS in filename");
                        SavePrefs = new File(SavePrefs.getAbsolutePath() + ".CMM");
                   // continue with save code:
                   System.out.println("File Selected:" + SavePrefs.toString());
                   //Creates a .cmm file with a code in it containing the data from the first site tab.
                   FileOutputStream out; // declare a file output object
    PrintStream p; // declare a print stream object
                   try
    // Create a new file output stream
    out = new FileOutputStream(SavePrefs.toString());
    // Connect print stream to the output stream
    p = new PrintStream( out );
    p.print(_SitePropPanel);
    p.close();
    catch (Exception e)
    System.err.println ("Error writing to file");
                   JOptionPane.showMessageDialog(null,
                             "File is saved.");
              // not OK selected (cancel or.?)
         private void LoadPrefs() {
              File loadPrefs;
              // get filename:
              fc.setDialogTitle("Select Filename For Site Data");
              int result = fc.showOpenDialog(f);
              if (result == JOptionPane.OK_OPTION) {
                   loadPrefs = fc.getSelectedFile();
                   // default file extension ".CMM"
                   if (!loadPrefs.getName().endsWith(".CMM")) {
                        // filename does not meet requirements:
                        System.out.println("NO CMIMS in filename");
                   // continue with save code:
                   System.out.println("File Selected:" + loadPrefs.toString());
                   try
         // Open the file that is the first
         // command line parameter
         FileInputStream fstream = new
                                  FileInputStream(loadPrefs.toString());
         // Convert our input stream to a
         // DataInputStream
                             DataInputStream in =
         new DataInputStream(fstream);
         // Continue to read lines while
         // there are still some left to read
         while (in.available() !=0)
         // Print file line to screen
                                  System.out.println (in.readLine());
                             in.close();
         catch (Exception e)
                             System.err.println("File input error");
              JOptionPane.showMessageDialog(null, "Feature is not yet implemented.");
         }

    Oh and the GUI is a window with menus where the save feature resides, but the data is in tabbed panels. That is where the _SitePropPanel comes in. I know I want it to write the input from the panel and not the panel. What would would I use for that? I tried getInputContext().                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Best way to store and retrieve data in a text file

    I want to write to a text file and then in another Applescript read the same data into an array
    I'll have 5 lines of text data
    What would be the best format?
    CSV?
    XML maybe?
    Just a plain file with each line of data separated by pressing enter?
    Thanks
    Omar

    I agree with Frank - for just 5 lines, simple text is probably sufficient.
    However, if the point is just to pass data between two AppleScripts you could even use native AppleScript objects - for example, you could write the list (array) to the file and then read it back in directly, e.g:
    Write the data:
    -- create a list of any types:
    set myList to {"a string", 3.14159, "foo", {name:"Joe", age:21}}
    -- create a file
    set f to open for access (choose file name) with write permission
    -- write your (binary) data to it
    write myList to f
    -- and close the file
    close access f
    Now, separately, you can read it back:
    set x to read (choose file) as list

  • What is the best way to geotag photos with data from GPS Tracker Log (GPX format)?

    I just returned from a 4 month trip to Southeast Asia. Before I left, I set the time on my camera, a Canon 7D, to match the GPS time on my GPS tracker, a QStarz BT-Q1000X. Both times were set to UTC, also known as GMT.
    I have imported the data from the GPS log into Aperture as a GPX file. Now I would like to sync the location metadata on my photos with the data from the GPS log. How can I do this using Aperture 3?
    I seem to be having two problems:
    Aperture wants to shift the times based on which part of the track I drag the images onto. Since the camera and gps tracker times were sync'd, I do not want any shift.
    The time shifts that are displayed are 12 hours and a few minutes, rather than 0 hours and a few minutes.
    A few additional notes:
    When I imported the GPS track, Aperture automatically changed the time zone of the track to Asia/Ho Chi Minh City, which is correct (GMT+7).
    I have batch changed the images from Camera Time: UTC to Actual Time: GMT+7
    The time on my computer is US/Eastern Daylight Time (GMT-4), or Eastern Standard Time (GMT-5) when the photos where taken.
    Since I was gone for so long, and my GPS tracker memory is limited, I set the tracker to record a trackpoint once every 60 seconds.
    Is there a solution to my problems using Aperture 3, or should I start looking for third party applications to geotag the photos before importing them into Aperture?
    Thank you.

    I think the 12 hour discrepancy is more likely a result of the 12 hour difference between GMT+5 and GMT-7. The dates and times of the photos and the GPS track are displayed properly in Aperture. See the images below.

Maybe you are looking for