Process all files in a directory and its subdirectories

Hello all,
I want to write a program that processes separately all the files in a given directory. I would like to open folders in that directory (if any) and further process all the files contained in them as well. Any suggestions with some Java code to do this as time effectively as possible? Thanks in advance.

Hello Chuck,
thanks for answering. You probably meant: "Search the forum archive - maybe your question has already been discussed. This way you help people focus on topics that have not yet been resolved."
Generally http://forum.java.sun.com/thread.jspa?forumID=31&threadID=510545 suits well. My problem is however, that I would like to pass the absolute path (not the relative one) of the directory which content (including subdirectories if any) should be further processed. Any suggestions how to make it function with the absolute path passed as input argument to the program?

Similar Messages

  • I need applescript to change all files in a folder and its subfolders ending in .xlsx changed to .xlsb

    I need applescript to change all files in a folder and its subfolders ending in .xlsx changed to .xlsb

    try something like this:
    with timeout of 3600 seconds
      -- long timeout to because the Finder is horribly slow
              tell application "Finder"
      -- collects the files from a folder called "whatever" in your user home folder
                        set xlsbFiles to every file of entire contents of folder "Whatever" of home whose name extension is "xlsb"
                        repeat with thisFile in xlsbFiles
                                  set name extension of thisFile to "xlsx"
                        end repeat
              end tell
    end timeout
    you could make a more efficient script using System Events.app, but this will get the job done with a minimum of thought.

  • 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
    }

  • How to read a files in directory and its subdirectories

    I wants to read all files in directory, its subdirectory and further till end the files in the subdirectory of subdirectories.
    I have some idea the I can do this by using recursive function, using the functions isDirectory(), File.list() etc.
    How much you can please help me. (via code of logic)

    import java.io.*;
    import java.net.*;
    public class MyCon
    public static void main(String args[]) throws
    IOException
    File file=new File("c:/");
    openDirectory(file,"");
    System.in.read();
    static void openDirectory(File file,String indent)
    String[] string=file.list();
    String path=file.getAbsolutePath();
    for(int i=0;i<string.length;i++)
    File temp=new File(path+"/"+string);
    if(temp.isDirectory())
    openDirectory(temp,indent+" ");
    else
    System.out.println(indent+temp.getName());

  • Batch-process all files in a directory

    I'm relatively new to LabView. I'm using 5.1, and would like to open all the text files in a certain directory, and apply my formulaes to the data contained within each. How can I batch process a whole directory?

    Hi,
    first of all you need know names of files in your directory: for this purpose use File I/O / Advanced/List directory.vi. This vi get name of directory, pattern (*.txt for example) and returns array of path to files.
    For all path use Read From Spreadsheet File.vi that get name of file and return 1 or 2-d array of data.
    Now you can apply formula to data.

  • Show Thumbnail of all files in a folder and its subfolders

    Hi Guys,
    I want to set the Filter Panel (Adobe Bridge CS3) to "show all items in this folder and all its subfolders" through Java script on windows.
    From UI it is possible by clicking on icon buton present in the filter panel and content panel shows the files from current folder as well as from its subfolders.
    Can any one suggest some Java script to do it?
    -P. M. Mitchell

    Any solution?
    Good Luck.
    My
    Si
    tes

  • Processing multiple files in a directory and merging them with sample text

    Hi,
    I'm trying to use automator (or applescript, or cmd line) to perform a repetitive action on around 5,000 html files.
    Here's the problem, can anyone help with the solution.
    Sample text is in a file called sample.txt
    I want to add the sample txt content to every file in a directory of my choice.
    so the script would need to.
    1. work it's way through the directory content.
    2. For each file it would append the content of the sample.txt and re-save the file to the original file name.

    sorry but in your first message you said you wanted it at the end of the file. also, you didn't really answer my question. an html file in text form usually starts with <html><head>... (it can have other junk there too)
    and ends with ...</body></html>.
    how do you want to handle that?
    cycling through files is not a problem.
    if you are using shell script action you can do the following:
    1. get specified finder items (put the folder with your html files in there)
    2. get folder content
    3. run shell script (pass input as arguments)
    for f in "$@"
    do
    #your shell script here
    done
    In the above "$@" is treated as the ambient folder from step 1 and f as the unix path of an item in that folder.

  • [Bash] Massively replace text in all files of a directory

    Hi everybody,
    I wrote this small recursive function in order to massively replace some strings contained in all files of a directory (and all subdirectories). Any suggestions?
    replaceText() {
    # set the temporary location
    local tFile="/tmp/out.tmp.$$"
    # call variables
    local script="$2"
    local opts="${@:3}"
    browse() {
    for iFile in "$1"/*; do
    if [ -d "$iFile" ];then
    # enter subdirectory...
    browse "$iFile"
    elif [ -f $iFile -a -r $iFile ]; then
    echo "$iFile"
    sed $opts "s/$(echo $script)/g" "$iFile" > $tFile && mv $tFile "$iFile"
    else
    echo "Skip $iFile"
    fi
    done
    browse $1
    Syntax:
    replaceText [path] [script] [sed options (optional)]
    For example (it will replace "hello" with "hi" in all files):
    replaceText /home/user/mydir hello/hi
    Note: It is case-sensitive.
    Bye,
    grufo
    Last edited by grufo (2012-11-10 15:05:43)

    falconindy wrote:
    Yes, find is recursive and extremely good at its job.
    http://mywiki.wooledge.org/UsingFind
    Well
    falconindy wrote:Your lack of quoting is dangerous, as is your code injection in sed. I'm not sure why you're echoing a var inside a command substitution inside a sed expression, but it's going to be subject to word splitting, all forms of expansion, and may very well break the sed expression entirely, leading to bad things. A contrived example, but passing something like 'foo//;d;s/bar/' should effectively delete the contents of every file the function touches.
    So, if you consider it dangerous, you can adopt the whole "sed syntax" and confirm before continue...:
    replaceText() {
    # set the temporary location
    local tFile="/tmp/out.tmp.$$"
    # call variables
    local sedArgs="${@:2}"
    browse() {
    for iFile in "$1"/*; do
    if [ -d "$iFile" ];then
    # enter subdirectory...
    browse "$iFile"
    elif [ -f $iFile -a -r $iFile ]; then
    echo "$iFile"
    sed $sedArgs "$iFile" > $tFile && mv $tFile "$iFile"
    else
    echo "Skip $iFile"
    fi
    done
    while true; do
    read -p "Do you want to apply \"sed $sedArgs\" to all files contained in the directory $1? [y/n] " yn
    case $yn in
    [Yy]* ) browse $1; break;;
    * ) exit;;
    esac
    done
    Syntax:
    replaceText [parent directory] [sed arguments]
    Example:
    replaceText /your/path -r 's/OldText/NewText/g'
    or, if you want to work directly with the current directory...
    replaceText() {
    # set the temporary location
    local tFile="/tmp/out.tmp.$$"
    # call variables
    local sedArgs="$@"
    browse() {
    for iFile in "$1"/*; do
    if [ -d "$iFile" ];then
    # enter subdirectory...
    browse "$iFile"
    elif [ -f $iFile -a -r $iFile ]; then
    echo "$iFile"
    sed $sedArgs "$iFile" > $tFile && mv $tFile "$iFile"
    else
    echo "Skip $iFile"
    fi
    done
    while true; do
    read -p "Do you want to apply \"sed $sedArgs\" to all files contained in the directory $PWD? [y/n] " yn
    case $yn in
    [Yy]* ) browse $PWD; break;;
    * ) exit;;
    esac
    done
    Syntax:
    replaceText [sed arguments]
    Example:
    replaceText -r 's/OldText/NewText/g'
    What about?
    falconindy wrote:I'll also point out that declaring a function within a function doesn't provide any amount of scoping -- 'browse' will be declared in the user's namespace after running this function for the first time.
    See:
    function1() {
    function2() {
    echo "Ciao"
    function2
    function2 # error
    function1 # works

  • Creating an action that treats all files in a directory

    How can I make an action which changes the picture size and resolution for all files in a directory and saves the new versions of the files in a subdirectory?
    Thanks

    Macro Details wrote:
    First create your Sub directory. Then start the Action. Open file, Resisize save as (to Sub directory) then close the file.
    Now: File- Automate-Batch. Select your action and your folders and overide the open Command and the Save As Command.
    Frankly Norbert I think the Image processor way is easier but to each his own as they say.  

  • Aim to process all files in folders on desktop to run through photoshop and save in multiple locations

    Aim to process all files in folders on desktop to run through photoshop and save in multiple locations
    Part one:-
    Gather information from desktop to get brand names and week numbers from the folders
    Excluding folders on desktop beginning with "2" or "Hot"
    Not sure about the list of folders
    but I have got this bit to work with
    set folderPath to "Hal 9000:Users:matthew:Desktop:DIVA_WK30_PSD" --<<this would be gained from the items on the desktop
    set {oldTID, my text item delimiters} to {my text item delimiters, ":"}
    set folderName to last text item of folderPath
    set my text item delimiters to "_WK"
    set FolderEndName to last text item of folderName
    set brandName to first text item of folderName
    set my text item delimiters to "_PSD"
    set weekNumber to first text item of FolderEndName
    set my text item delimiters to oldTID
    After running this I have enough information to create folders in multiple locations, (i need to know where they are so that photoshop can later save them in those multiple locations
    So I need the following folders created
    Locally
    Hal 9000:Users:matthew:Pictures:2011-2012:"WK" + weekNumber
    Hal 9000:Users:matthew:Pictures:2011-2012:"WK" + weekNumber: brandName
    Hal 9000:Users:matthew:Pictures:2011-2012:"WK" + weekNumber: brandName: brandName + "_WK" + weekNumber + "_LR" --(Set path for Later)PathA
    Hal 9000:Users:matthew:Pictures:2011-2012:"WK" + weekNumber: brandName: brandName + "_WK" + weekNumber + "_HR"--(Set path for Later)PathB
    Network
    Volumes:GEN:Brands:Zoom:Brands - Zoom:Upload Photos:2012:"Week" + weekNumber
    Volumes:GEN:Brands:Zoom:Brands - Zoom:Upload Photos:2012:"Week" + weekNumber:brandName + "_WK" + weekNumber + "_LR"  --(Set path for Later)PathC
    Volumes:GEN:Website_Images --(no need to create folder just set path)PathD
    FTP (Still as a normal Volume) So like another Network
    Volumes:impulse:"Week" + weekNumber
    Volumes:impulse:"Week" + weekNumber:Brand
    Volumes:impulse:"Week" + weekNumber:Brand:brandName + "_WK" + weekNumber + "_LR"  --(Set path for Later)PathE
    Volumes:impulse:"Week" + weekNumber:Brand:brandName + "_WK" + weekNumber + "_HR"  --(Set path for Later)PathF
    I like to think that is end of Part 1
    Part 2
    Take the images  (PSD's) from those folders relevant to the Brand then possibly run more applescript that opens flattens and then saves it in the locations above.
    For example….
    An image in folder DIVA_WK30_PSD will then run an applescript in Photoshop, lets call it DivaProcessImages within this we then save to PathA, PathB, PathC, PathD, PathE, PathF the folder path of C should therefore look like this
    Volumes:GEN:Brands:Zoom:Brands - Zoom:Upload Photos:2012:Week30:DIVA_WK30_LR and of course save the image as original filename.
    Then from the next folder
    An image in folder Free_WK30_PSD will then run an applescript in Photoshop, lets call it FreeProcessImages within this we then save to PathA, PathB, PathC, PathD, PathE, PathF the folder path of C should therefore look like this
    Volumes:GEN:Brands:Zoom:Brands - Zoom:Upload Photos:2012:Week30:Free_WK30_LR and of course save the image as original filename.
    The photoshop applescript i'm hoping will be easier as it should be a clearer step by step process without any if's and but's
    Now for the coffee!!

    Hi,
    MattJayC wrote:
    Now to the other part, where each folder was created (and those that already existed) how do I set them as varibles?
    For example,
    set localBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_HR", localBrandFolder)
    This line was used to create more than one folder as it ran though the folders on the desktop. The next part is I will need to reference them to save files to them.
    You can use a records
    Examples
    if you want the path of localBrandFolder_High_Res  of "Diva", if "Diva" is the second folder of the Desktop
    You get the path with this : localBrandFolder_High_Res of record 2 of myRecords
    if you want the path of localWeekFolder  in the first folder of the Desktop
    You get the path with this : localWeekFolder of record 1 of myRecords
    Here is the script
    set myRecords to {}
    set dtF to paragraphs of (do shell script "ls -F ~/Desktop | grep '/' | cut -d'/' -f1")
    repeat with i from 1 to number of items in dtF
        set this_item to item i of dtF
        if this_item does not start with "2_" and this_item does not start with "Hot" then
            try
                set folderPath to this_item
                set {oldTID, my text item delimiters} to {my text item delimiters, ":"}
                set folderName to last text item of folderPath
                set my text item delimiters to "_WK"
                set FolderEndName to last text item of folderName
                set brandName to first text item of folderName
                set my text item delimiters to "_PSD"
                set weekNumber to first text item of FolderEndName
                set my text item delimiters to oldTID
            end try
            try
                set this_local_folder to "Hal 9000:Users:matthew:Pictures:2011-2012"
                set var1 to my getFolderPath("WK" & weekNumber, this_local_folder)
                set var2 to my getFolderPath(brandName, var1)
                set var3 to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", var2)
                set var4 to my getFolderPath(brandName & "_WK" & weekNumber & "_HR", var2)
                --set up names to destination folders and create over Netwrok including an already exisiting folder
                set this_Network_folder to "DCKGEN:Brands:Zoom:Brand - Zoom:Upload Photos:2012:"
                set var5 to my getFolderPath("WK" & weekNumber, this_Network_folder)
                set var6 to my getFolderPath(brandName, var5)
                set var7 to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", var6)
                set website_images to "DCKGEN:Website_Images:"
                --set up names to destination folders and create over Netwrok for FTP collection (based on a mounted drive)
                set this_ftp_folder to "Impulse:"
                set var8 to my getFolderPath("Week" & weekNumber, this_ftp_folder)
                set var9 to my getFolderPath(brandName, var8)
                set var10 to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", var9)
                set var11 to my getFolderPath(brandName & "_WK" & weekNumber & "_HR", var9)
                set end of myRecords to ¬
      {localWeekFolder:var1, localBrandFolder:var2, localBrandFolder_Low_Res:var3, localBrandFolder_High_Res:var4, networkWeekFolder:var5, networkBrandFolder:var6, networkBrandFolder_Low_Res:var7, ftpWeekFolder:var8, ftpBrandFolder:var9, ftpBrandFolder_Low_Res:var10, ftpBrandFolder_High_Res:var11}
            end try
        end if
    end repeat
    localBrandFolder_High_Res of record 2 of myRecords -- get full path of localBrandFolder_High_Res in the second folder of Desktop
    on getFolderPath(tName, folderPath)
        tell application "Finder" to tell folder folderPath
            if not (exists folder tName) then
                return (make new folder at it with properties {name:tName}) as string
            else
                return (folder tName) as string
            end if
        end tell
    end getFolderPath

  • How to Zip server files(in a directory) and throwing back to client

    Can someone tell me how to zip all the files in a particular directory of my web application and throwing back to client to give option for save that zipped file.
    i have used the below used function to zip in servlet. But I cann't zip a particular directory of my application in server.
    Please help
    private void zipDir(String dir2zip, ZipOutputStream zos)
    try
    //create a new File object based on the directory we
    // have to zip File
    File fileDir2Zip = new File(dir2zip);
    System.out.println("is directory ..."+fileDir2Zip.isDirectory());
    //get a listing of the directory content
    String[] dirList = fileDir2Zip.list();
    for(int i = 0 ; i < dirList.length ; i++)
    System.out.println("Dir list ..."+dirList);
    byte[] readBuffer = new byte[2156];
    int bytesIn = 0;
    //loop through dirList, and zip the files
    for(int i=0; i<dirList.length; i++)
    File f = new File(fileDir2Zip, dirList[i]);
    if(f.isDirectory())
    //if the File object is a directory, call this
    //function again to add its content recursively
    String filePath = f.getPath();
    zipDir(filePath, zos);
    //loop again
    continue;
    //if we reached here, the File object f was not
    //a directory
    //create a FileInputStream on top of f
    FileInputStream fis = new FileInputStream(f);
    //create a new zip entry
    ZipEntry anEntry = new ZipEntry(f.getPath());
    //place the zip entry in the ZipOutputStream object
    zos.putNextEntry(anEntry);
    //now write the content of the file to the ZipOutputStream
    while((bytesIn = fis.read(readBuffer)) != -1)
    zos.write(readBuffer, 0, bytesIn);
    System.out.println("Last");
    //close the Stream
    fis.close();
    catch(Exception e)
    e.printStackTrace();

    Hi
    Whatever file exist in directory should execute with out any condition because they delete all files after exection of my process chain. They are using another process chain once a day for deletion of all files in that directory.
    So directory always contains fresh files.
    Here by using routine in infopackge i am unable to run all files one by one at a time.
    As of my knowledge  by using infopackage we can run only one file at a time.
    Here my question is , can we run more than one file in single run of infopackage?
    or can we have any function module to run the infopackage from externally? so that i can use function module in abap program? any ideas..
    Regards
    Raju

  • Is it possible to compare all files in a directory?

    Hi
    Is it possible to iterate through all the files in a directory and compare them? i know how to compare two files, but i need to compare about 576.
    cheers for any advice
    ness

    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
    }

  • Sender File Adapter stop processing all files

    Hello all,
    the file adapter pick up all files in the directory by default.
    if  a large number of files are in the directory then this could slow down the pi processing.
    is there any way to process only one file per polling??
    regards

    >
    Ralf Zimmerningkat wrote:
    > Hello all,
    > the file adapter pick up all files in the directory by default.
    > if  a large number of files are in the directory then this could slow down the pi processing.
    > is there any way to process only one file per polling??
    >
    > regards
    I do not have any proble if you have got the answer. BUT this blog says how to exclude the other files from the same folder.
    Your Case: For example, Your Sender CC wants to pick up file ABC.txt from /xyz dir, now suppose there are 10 thousand files of same name in the dir and you want ABC.txt should be picked up one by one, So how this blog is going to help you. Can you Plz explain to me and others too?
    @Sachin may be you can throw some light on this... may be I am missing something.

  • I want read PDF file from SAP directory and create a spool request or print

    Hi all,
    I want read PDF file from SAP directory and create a spool request or print the pdf through SAP. Can any body  help me in this.
    Also please write to me if its possible to open PDF from SAP directory to adobe pdf reader.
    Thanks in advance,
    Sunny

    Hi Sunny,
    Check these links.
    http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm
    http://www.erpgenie.com/sap/abap/pdf_creation.htm
    http://www.geocities.com/mpioud/Z_EMAIL_ABAP_REPORT.html
    http://www.thespot4sap.com/Articles/SAP_Mail_SO_Object_Send.asp
    http://www.sapdevelopment.co.uk/reporting/email/attach_xls.htm
    Hope this resolves your query.
    Reward all the helpful answers.
    Regards

  • To set a directory and its subdirectory in  utl_file_dir using command

    Hi all ,
    Please help me in this dbt .
    in one article i saw
    UTL_FILE_DIR lets you specify one or more directories that Oracle should use for PL/SQL file I/O. If you are specifying multiple directories, you must repeat the UTL_FILE_DIR parameter for each directory
    on separate lines of the initialization parameter file
    and in another alter system set utl_file_dir=dir1,dir2 scope=both;
    whther the second method is possible
    if i want to have a directory and its sub directory to set in utl_file_dir
    what i should do , whether i want to specify main directory and all sub directory seperated by comma or any other method is there
    Please help me
    thanks in advance ..........

    Instead of specifying the directory in the INIT.ora file u can use Directory object.
    U need to create a directory object once & use it when ever u require it.
    For example
    CREATE OR REPLACE DIRECTORY Test_dir AS 'C:\abc'
    Now you can use this directoryTEST_DIR in any Pl Sql block provided u have proper privileges.

Maybe you are looking for

  • Can i set up a spare box in my bedroom?

    Im sorry if this has been asked a million times but ive had a look at a few posts but theyre not specific. Also, im not familiar with too much tech talk. The new house had already black box (which we watch freeview on now) and a hub but obviously the

  • The Health Service could not log on the RunAs account ...event ID 7000 Health Service

    Hello everyone, While using the Web Application Transaction Monitoring to monitor certain websites using specific credentials, this Event 7000 occures on the Watcher Nodes which happen to be also Management Servers. Here are the details: The Run As A

  • Need an efficient String searching algo

    Hi ! i'm in desperate need of the algorithm i hope some of you may already have it. actually i'm developing a chat application and i need to implement the functionality of inserting images on finding special tokens in the text..i'm using JTextPane an

  • Time machine - 1st backup - stuck on calculating size

    Hello, I'm running Time Machine for the first time on OSX Lion. I've bought a external 2,5inch HD of 1TB. I formatted it to Mac Os X Extended (Journaled). I added the disk as a time machine backup and ran the "backup now". It's stuck on Calculating S

  • How to download all files from a shared workspace

    Is there a way to download your entire workspace contents locally to my computer?