Group the files based on their extensions

Hi,
I am traversing a dir and listing all the files under that directory. Now i want to group the files based on the extension and just print the number of files with each extension.
ex:
Extension No.of Files Size of the files
.java 10 23455 bytes
.html 2 1000 bytes
I am able to get the extension of the files. I would like to know how to proceed after that.
Any sample code will be helpful.
Regards
Kutty

I have used a method to list all the files in the directory. After adding files with same extension to the HashMap. i am printing files after reading file by file. I need to print the files once i complete reading all the files in the directory.
Any suggestions?
private void listingFiles(File f )
          Map extensionMap = null;
          File[] files = f.listFiles();
          for( int i = 0; i < files.length; i++ )
               File file1 = files;
               Dprop.size += files[i].length();
               if (file1.isFile())
                    fcount = fcount +1;     
                    if (extensionMap == null)
                         extensionMap = new HashMap();
                         // Group files by extension
                         for(int idx = 0; idx < files.length; idx++)
                              if (files[idx].isFile() && files[idx] != null)
                                   String ext = getExtension(files[idx]); // get the extension
                                   ext = ext.toLowerCase();
                                   List fileList = (List)extensionMap.get(ext);
                                   if(fileList == null)
                                   fileList = new ArrayList();
                                   extensionMap.put(ext, fileList);
                                   fileList.add(files[idx]);
                    // Access all the files by extension
                         for(Iterator extensionIterator = extensionMap.keySet().iterator(); extensionIterator.hasNext(); )
                              String ext = (String)extensionIterator.next();
                              List fileList = (List)extensionMap.get(ext);
                              System.out.println("\n\nNo of Files "+fileList.size()+" with extension '"+ext+"' in '"+f+ "' Directory");
                              for(Iterator fileIterator = fileList.iterator(); fileIterator.hasNext(); )
                                   File file = (File)fileIterator.next();
                              System.out.println("File Name "+file+" File Size "+file.length());
               else
                    dcount = dcount +1;
                    listingFiles( file1 );
Thanks in advance
Kutty

Similar Messages

  • SSIS package to order all the CSV files based on their date of creation/modification mentioned in a filename and load the least recent file in oracle Destination

    HI,
    I need a help for creating SSIS package which has flat file source (specifically , delimited csv files) which are placed in a shared folder
    having file names as  File_1_2015-04-30 08:54:13.900.csv, File_2_2015-04-30 07:54:13.900.csv.
    So, I wanted to use foreach loop to find out the oldest file amongst that(through script task) and need to transform that file in Oracle Destination. After that, I want to archive that file and need to continue this action uptil the most recent file gets
    loaded in destination.
    So, Could you guys please guide me?
    Thanks in advance

    I'd say you need two loops, one to cycle through all the files and collect their names. Then sort them based on your criterion
    Perhaps you can start by seeing http://www.sqlis.com/sqlis/post/Looping-over-files-with-the-Foreach-Loop.aspx
    Collect the file names into a Recodset Destination, then shred it http://www.sqlis.com/sqlis/post/Shredding-a-Recordset.aspx
    perhaps you need an outer loop to iterate over each file to compare the files for dates.
    Do each piece and post here where you needed to stop.
    Arthur
    MyBlog
    Twitter

  • How to group the output based on DAYS field

    Hi
    I am modifying the predefined ALV report "RFTMBL01" .I had added the days field to that report output and I have to group the output based on the DAYS field
    Records within 0-10 days in one group
    Records within 10-30 days in one group
    Records above 30 days should be  one group
    No of days may repeat that means with no of days 10 .many records will be there
    There is also a field by name "AMOUNT" in my output.
    I have to calculate SUBTOTALs at the end of every group and at the end of the report i should caluculate GRAND TOTAL.
    Please remember that i should not use any any BLOCKED ALVs and for Totals i should not use the SYMBOLS provided in the application toolbar of the report
    Thanks in Advance

    <b>>>>The file has to be routed based on the Company Code</b>
    check with xpaths.
    /people/shabarish.vijayakumar/blog/2006/06/07/customise-your-xpath-expressions-in-receiver-determination
    /people/shabarish.vijayakumar/blog/2005/08/03/xpath-to-show-the-path-multiple-receivers
    <b>>>>different file should have different file name again based on the company code.</b>
    /people/jayakrishnan.nair/blog/2005/06/20/dynamic-file-name-using-xi-30-sp12-part--i
    /people/jayakrishnan.nair/blog/2005/06/28/dynamic-file-namexslt-mapping-with-java-enhancement-using-xi-30-sp12-part-ii

  • Pick a file based upon its extension

    Hi Experts,
    I have a requirment. I have to pick a file based upon its extension, i.e., the file having a particular extension, should be picked up before fiiles having a diferent extension.
    Is this possible using only the adapter configuration?
    Thanks and Regards,
    Sanjeev.

    Hi Sanjeev ,
    Have a look at following PDF .These will be helpful to create your Road map
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/4f61fddf-0601-0010-7ab5-fb749538f6ab
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/d458a870-0601-0010-caab-b99c79741964
    /people/krishna.moorthyp/blog/2005/06/09/walkthrough-with-bpm
    BPM Steps..
    http://help.sap.com/saphelp_nw04/helpdata/en/62/dcef46dae42142911c8f14ca7a7c39/frameset.htm
    /people/shabarish.vijayakumar/blog/2006/11/26/adapter-scheduling--hail-sp-19-
    Reward points if it is useful
    Thanks
    Sunil Singh

  • Oracle SQL Developer  error - "The file-based source procedure Name is not present in the database."

    I recently started working on the Oracle SQL developer. I have 'select' privileges on the QA schema and when tried to execute proc in QA. It is giving the error as 'The file-based source <procedure Name>  is not present in the database.  Was it compiled?'
    instead 'you do not have sufficient privileges to execute this procedure'. Did research on internet but with no luck.What configuration changes needed to be done to make it work.Guide me.

    Sounds like you do not have the correct privileges.  What should have been granted to you by the QA user, or some other user with appropriate privileges, is...
    grant EXECUTE on "QA"."<PROCEDURE_OF_INTEREST>" to "<YOUR_USERID>" ;
    Note that a grant of execute on a procedure has nothing to do with grants of select on some or all of QA's tables and views.
    So, as Vadim suggests, from your connection node in SQL Developer's Connections view, if you expand the Other Users node, then expand QA and look in the Procedures node, do you see the procedure of interest?  If not, you cannot expect to be able to execute it from your userid's connection. And even if you do see it, you may have some other privilege that permits viewing but not executing, like...
    The role SELECT_CATALOG_ROLE
    The system privilege SELECT ANY DICTIONARY
    And even if you do not see it there, then having certain other privileges granted to you could permit executing it in general, like...
    The role EXECUTE_CATALOG_ROLE
    The system privilege EXECUTE ANY PROCEDURE
    Also, note that the 3.0 release is a bit dated nowadays. Upgrading to 4.0.3 production or even the 4.1 EA2 (early adopter) release will, in general, give you a better experience.
    Best wishes,
    Gary

  • To test how can we use the opt  'logical file name' to name the file based

    Hi Sir/Madam,
               to test how can we use the opt  'logical file name' to name the file based on the selection made in the dtp run for extracting data as flat file.

    Hi Vishali,
    In the DTP select the file location as application server and give the logical file path. The actual file and logical path can be created using transaction "FILE" and "AL11".
    Rest of the process is same as that of extraction from local file.
    Regards,
    Durgesh.

  • I started to learn HTML, and I'm using text edit and everything is going fine, when I save the file with a .html extension and open it with safari I only view the code and not the webpage that was supposed to be created.

    I started to learn HTML, and I'm using text edit and everything is going fine, when I save the file with a .html extension and open it with safari I only view the code and not the webpage that was supposed to be created.

    That is because you don't have a web server configured and running to serve the html page. In order to see the page in a browser you need to access it using a url similar to http://localhost/~yourUserName if you are serving the page from your user account.
    Prior to Mountain Lion you could go into web sharing and turn on the web server. With Mountain Lion there is no option, other than using terminal, to turn on the web server. The web sharing menu item has been removed in Mountain Lion. Apache is still on your computer but it will take a little searching these forums or the Internet to find how to turn it on.
    If you want a graphic user interface to turn on/off the Apache server you could download and install a server application like xampp, http://www.apachefriends.org/en/xampp.html. I use this and it works well.

  • Classyfying the customers based on their sales

    Hi,
    I have report showing the cutomers and the sales units to them
    for example:
    customer     sales
    A     200
    B     300
    C     50
    D     100
    how can i grade the customers based on their sales, for example
    Grading                customer     sales
    Gold >=300            B              300
    Sub total                   300
    silver >100 & <300    A              200
    sub total                   200
    Bronze <=100          C               50
                       D              100
    sub total                   150
    Could anyone please help me
    Message was edited by:
            rapo
    Message was edited by:
            rapo

    Thanks ganesh and ramesh,
    Thanks for your inputs.
    By exceptions, i can get classigy them and even color them and sort them but i cannot get the sub totals for each classification.
    Ramesh, can you please clarify in detail how this can be done by using the formula.
    thanks and regards

  • How to Capture the File Names of any extension using ssis

    Hello,
    Can you please let me know on how to Capture the File Names of any extension(EG : xls,text,.csv etc) at a time  and stores in excel file  using SSIS?
    Any help would be appreciated.
    Thanks,
    Vinay s

    If you need to act differently on each file type separately or if not all types of files are wanted, i.e. the Filespecifier cannot be *.* in the Foreach loop:
    In the ssis package
    make 3 variables:
    to store the file extension, e.g. User::CurrentExtension of type string
    to store the filename found in the directory: @CurrentFilename
    to store the name of the directory where the files reside e.g. User::CurrentDirectory
    make a foreach loop of type Foreach Item enumerator:
    in the items list you add each file extension that you need
    txt
    csv
    xls
    xlsx
    As Variable mappings map the CurrentExtension to Index 0
    Inside this foreach loop add another foreach loop of type Foreach File enumerator, in the collection Expressions
    add Expression Directory , set to @[User::CurrentDirecotry]
    add Expression FileSpec, set to "*." + @[User::CurrentFileExtension]
    In the Variable mappings, map Variable user::CurrentFilename to Index 0
    Inside this loop use Execute SQL Task to insert the filename in a Excel connection.
    Jan D'Hondt - SQL server BI development

  • Pickup the file based on the date in file name

    Dear all,
    I have requirement like this.
    EX:
    I have file name called ABC_20110721.txt , i have to pickup that file today and should not delete it and should not mark as 'Read only'. We have to keep that file as is in FTP.
    I will have another file tomorrow like ABC_20110722.txt , i have to pickup this file alone.
    So that means date in the file name is dynamic based on the system date( current date interface runs on )
    Please let me know how can we do this?
    Regards

    Hi ,
        You have not specified your operating system on which PI is running.  You need scripts to achieve this for you. In case you are using UNIX/Solaris/Linux server the following script "filename.sh" should run fine
    lines=`expr 0 + 0`
    maxlines=`expr 0 + 100`
    while [ 1 -le 5 ] ; do
         d=`date +%G%m%d`
         count=`ls -1 | grep $d |wc -l`
         c=`expr $count + 0`
         while [ $c -gt 0 ]; do
              file=`ls -1 | grep $d |tail -$c |head -1`
              searchFile=`grep $file temp | head -1 | wc -l`
              searchFile=`expr $searchFile + 0`
              if [  $searchFile -eq 0 ]; then
                   cp $file /home/anghosh0/sdn/f
                   echo $file >>temp
                   lines=`expr $lines + 1`
              fi
              c=`expr $c - 1`
         done     
         if [ $lines -gt $maxlines ]; then
                k=`date +%G%m`
              grep $k temp > t
              mv -f t temp
              lines=`expr 0 + 0`
         fi     
    done
    Say you are poutting the source files say ABC_20110721.txt,ABC_20110722.txt,ABC_20110725.txt  in a directory. Say the name of the directory is    "/usr/home/dx7" . You have to put this scipt "filename.sh" in  "usr/home/dx7".  Set the permission bits of this script to "777" or you can use command "chmod 777 filename.sh". This script will choose only the files for todays date as per server time. This script is running in an infinite loop. Thus whenever there is a new file in the directory it checks the file name, and if the name contains todays date, it puts the file in "home/anghosh0/sdn/f" directory from where PI server picks it up for reading. Please change the folder name according to your convinience. Now in the folder "/usr/home/dx7" you need to keep a file called "temp" this file will conatin only one word or any symbol say "hi". The use of temp is to collect all file names that the script has already transferred to PI folder. Thus if script has transferred file say "ABC_20110725.txt " and "DEF_20110725.txt ", then "temp" will have contents
    hi
    ABC_20110725.txt
    DEF_20110725.txt
    This prevents same file being put to PI source directory twice. Once temp reaches a maximum of 100 lines, this script clears the contents of temp automatically, except for the lines which belong to current year and current month. You can alter this value by altering the line "maxlines=`expr 0 + 100`" in the script shown above.
    This is because the file grows in length over time.Please take help of you BASIS team to put this file in correct folder and run it. It is working fine in our Linux server. Please run this as a background process with this command "filename.sh &".
    I think this will solve your problem. In case your operating system is windows then Please let me know I need to write batch file for the same.
    regards
    Anupam
    Edited by: anupamsap on Jul 26, 2011 8:18 AM

  • Back-up of Specific Files based on their Time Stamp

    I use Time Machine, but I have 3 folders I like to back-up more frequently. I currently drag and drop them onto an external disk drive. This causes the Copy window to appear that says "An item named “XXXX” already exists in this location. Do you want to replace it with the one you’re moving? Apply to all?" etc. It then proceeds to write ALL files whether they have changed or not.
    What I'm looking for is an app that does basically the same thing EXCEPT only re-writes the file if it has changed based on the time stamp of the file. Also, if the file is no longer in the source folder, it will delete it in the back-up folder. And if it hasn't changed, doesn't bother to re-write it and leaves it untouched, saving substantial time.
    To be clear, I'm not looking for "Syncing" folders! I just want to back-up those files that have changed.
    Thanks!

    RalphTomaccio wrote:
    I use Time Machine, but I have 3 folders I like to back-up more frequently.
    More often than hourly?
    What I'm looking for is an app that does basically the same thing EXCEPT only re-writes the file if it has changed based on the time stamp of the file. Also, if the file is no longer in the source folder, it will delete it in the back-up folder. And if it hasn't changed, doesn't bother to re-write it and leaves it untouched, saving substantial time.
    CarbonCopyCloner and SuperDuper can do that, but I don't think you can schedule them more often than once per hour. They're used most often to make "bootable clones," but would work for your purpose as well. I don't use SD, but on CCC you could set up a "Scheduled task" and run it manually when desired.
    [CarbonCopyCloner|http://www.bombich.com> is donationware; [SuperDuper|http://www.shirt-pocket.com/SuperDuper/SuperDuperDescription.html] has a free version, but you need the paid one (about $30) to do updates instead of full replacements, or scheduling.
    You might want to investigate the Chronosync app; it might work, too.
    And/or, see Kappy's post on [Basic Backup|http://discussions.apple.com/thread.jspa?messageID=12366915#12366915].
    If you can wait until summer, and upgrade to Lion, it's "AutoSave" and/or "Versions" features might be helpful, too. See http://www.apple.com/macosx/lion/

  • How can I rename files based on their ID3 tags?

    For example I would like to rename the files in a particular folder to have the format <track number> - <track name>.mp3
    I'd rather not used third party software to do this.

    For example I would like to rename the files in a particular folder to have the format <track number> - <track name>.mp3
    I'd rather not used third party software to do this.

  • BPM : Procees the file based on the response of Webservice

    Hi
    I have a scenario where two files are the source..and the target is Webservice
    Based upon the response of the first file ....i want to process the sencond file
    if not i want to raise an exception...
    whar are the steps i have to use in BPM..
    SV

    SV,
    Steps are mention below
    1. 2 Receive Step - To recieve data from files also define corelation
    2. Send Step - Call webservice
    3. Switch Step - To check whether response is ok
    4. If the condition true then process the second file.
    5. If condition fails raise an exception message
    Gaurav Jain

  • P routers have no knowledge of the customer prefixes, they just Label switch the packets based on their LFIB

    Here is a scenrio,
    (1.1.1.0)CE1-PE1-P-PE2-CE2(2.2.2.0)
    P router has no customer routes in its routing table, since it is not participating in iBGP.. thats perfect....
    but P routers are meant to label switch packets between CE-1 & CE-2 through PE1 & PE2.. but i cannot see any labels for customer routes in P LFIB:
    /* Style Definitions */
    table.MsoNormalTable
    {mso-style-name:"Table Normal";
    mso-tstyle-rowband-size:0;
    mso-tstyle-colband-size:0;
    mso-style-noshow:yes;
    mso-style-priority:99;
    mso-style-qformat:yes;
    mso-style-parent:"";
    mso-padding-alt:0in 5.4pt 0in 5.4pt;
    mso-para-margin-top:0in;
    mso-para-margin-right:0in;
    mso-para-margin-bottom:10.0pt;
    mso-para-margin-left:0in;
    line-height:115%;
    mso-pagination:widow-orphan;
    font-size:11.0pt;
    font-family:"Calibri","sans-serif";
    mso-ascii-font-family:Calibri;
    mso-ascii-theme-font:minor-latin;
    mso-hansi-font-family:Calibri;
    mso-hansi-theme-font:minor-latin;}
    P#sh mpls for
    Local  Outgoing    Prefix            Bytes tag  Outgoing   Next Hop
    tag    tag or VC   or Tunnel Id      switched   interface
    16     Pop tag     10.10.10.11/32    6703       Se0/1      point2point
    17     Pop tag     10.10.10.10/32    2140       Se0/0      point2point

    Hi Mukarramjahraheel 
    You are right . P will not participating in iBGP. He is not aware of any Customer router of BGP VPNv4 route..
    P Router know only internal IGP. Please go through the below points.
    The JOB of Core router is to propogate the route As Fast As Possible without delay.
    Don't Get confuse in MPLS . MPLS is used for only  Fast switching . Whouth MPLS also you can RUN  VRF kown as VRF - Lite , BGP - AF & use CEF for fast switching.
    Before Going Further Please check you Design = Whether You want to Create Full Mesh IBGP  or Go With  BGP Route Reflector.
    Communication from CE to PE
    PE routers translate into VPN-V4 route
    Assigns an RD, SOO (if configured) and RT based on configuration
    Re-writes Next-Hop attribute  (to PE loopback ) -- When PE Re-Write the Next HOP , That next hop will  IBGP VPNv4 Neighbore PE and that is reachable through internal IGP. MPLS work only for Internal IGP to forward the packet AFAP without delay .
    Assigns a label based on VRF and/or interface
    Sends MP-BGP update to all PE neighbors
    Receiving PE routers translate to IPv4Insert the route into the VRF identified by the RT
    attribute (based on PE configuration)The label associated to the VPN-V4 address will be set onpackets forwarded towards the destination

  • How do I select the items based on their adjacent equality?

    In the below table,
        DECLARE @t1 TABLE(id INT,NAME VARCHAR(MAX))
        INSERT INTO @t1 VALUES(1,'test')
        INSERT INTO @t1 VALUES(2,'test')
        INSERT INTO @t1 VALUES(3,'best')
        INSERT INTO @t1 VALUES(4,'rest')
        INSERT INTO @t1 VALUES(5,'rest')
    how can I select the records that have equals values coming adjacently? That is I am running an SQL job. It should take the adjacent equal value  count for its processing. In the below table, first time the job is running it should take count as 2 the
    2nd time job is running it should be 1. Third time it should be 2. What is the query that will fetch the cont of equal records for name column? In case no equal columns it should be 1. Please help
    mayooran99

    Hi
    Try the following code.
    DECLARE @t1 TABLE(id INT,NAME VARCHAR(MAX))
    INSERT INTO @t1 VALUES(1,'test')
    INSERT INTO @t1 VALUES(2,'test')
    INSERT INTO @t1 VALUES(3,'best')
    INSERT INTO @t1 VALUES(4,'rest')
    INSERT INTO @t1 VALUES(5,'rest')
    INSERT INTO @t1 VALUES(6,'test')
    INSERT INTO @t1 VALUES(7,'best')
    INSERT INTO @t1 VALUES(8,'best')
    INSERT INTO @t1 VALUES(9,'vest')
    --ranking adjacent names, running total
    SELECT rs.id, rs.NAME, ROW_NUMBER() over (partition by name, nxt_id order by id) RankingCount
    FROM (
    SELECT nxt.id, nxt.NAME,(SELECT min(s.id)
    FROM @t1 s
    WHERE s.name <> nxt.name
    AND s.id > nxt.id
    ) as nxt_id
    FROM @t1 nxt) rs
    ORDER BY rs.id;
    --code to just return the totals
    with cteTotals
    as
    SELECT rs.id, rs.NAME, ROW_NUMBER() over (partition by name, nxt_id order by id) RankingCount, nxt_id, ROW_NUMBER() over (partition by name, nxt_id order by id desc) Ranking
    FROM (
    SELECT nxt.id, nxt.NAME,(SELECT min(s.id)
    FROM @t1 s
    WHERE s.name <> nxt.name
    AND s.id > nxt.id
    ) as nxt_id
    FROM @t1 nxt) rs
    select Name, RankingCount
    from cteTotals
    WHERE Ranking=1
    order by id
    The first query keeps a running total of adjacent names, the second one just reports the totals

Maybe you are looking for

  • Error while creating IDOC from payment run

    Dear All, I 've alredy done all EDI settings for creating IDOC from payment run. But system in not generating IDOC as end with a result as "House bank is not designated as a EDI Partner'. Please suggest how to define house bank as a EDI partner. Rega

  • Partial reversal of the payment document

    Hi gurus,   I have a payment document A, that contains 3 invoices - C, D and E. Issit possible to reverse just invoice C in payment document A without having to do a new payment run?   As far as I know, once you reset ( FBRA ) payment document A, inv

  • Private dictionaries and Namespaces

    Private dictionaries and Namespaces We ran into an issue with some email templates in converting from RC2006 to RC2008.3 where Namespace values from Private service dictionaries were not populating correctly in RC2008. In the upgrade process from RC2

  • How can I make a Splitting in Cost center accounting by Cost elements?

    Hi experts: I have defined a splitting structure and I would like to split the cost bettew fixed and variables cost. To to that I have defined two different assignments and in the selection for each assignment  I have completed the "Field label" with

  • ITunes 11.0.4 does not sync with iPhone 5

    I'm running Windows 8 (64bit). Installed the above and tried to sync, it can detect my iPhone 5, it can sync with my photos, but it can't sync with my music, movies and tones. There are some other songs, movies and tones already in my iPhone so when