Batch Script to display last modified file from multiple directories

Hello,
I am trying to find the name of the latest file  or the last modified file from a set of given directories.
I approached the problem by breaking it into two parts: a.  read all the directories from a .txt file and display the names of those directories and files under those directories.  b. Find the latest file present in any given directory and
Upto this point all worked well, but when I am trying to combine both these batch scripts, I am unable to get the desired result.
I am using BATCH SCRIPT only to complete this.
My tried script is as below:
a.  TO SEE ALL THE DIRECTORIES SPECIFIED IN "path_123.txt" FILE
for /f "delims=" %%i in ('type "C:\Users\sonkar\Desktop\path_123.txt" ') do (set locall=%%i
echo %locall%
echo %%i
b.  TO FIND THE LATEST FILE PRESENT IN THE DIRECTORY
set BUILDDROP="E:\"
for /f "tokens=*" %%a in ('dir /A:-D /B /O:-D %BUILDDROP%') do set NEWEST=%%a&& goto :next
:next
echo %NEWEST%
But when combining both is not working at all.
Any help is appreciated.

Since batch files lack the ability to do date arithmetic you are pushing them well beyond their limits. Either VBScript of PowerShell could handle this type of task. Here is a VBScript solution. You must save the code in a .vbs file, then modify it to suit
your exact needs.
'Find the most recent file in a collection of folders
'11 Sep 2014 FNL
Dim dDate, dDate_, sFile, sFile_
Set oFSO = CreateObject("Scripting.Filesystemobject")
Set oList = ofso.OpenTextFile("C:\Users\sonkar\Desktop\path_123.txt", 1)
aList = Split(olist.ReadAll, vbCrLf)
oList.close
dDate = cdate("01/01/2000")
For Each sFolder In aList
    dDate_ = cdate("01/01/2000")
    ProcessFolder(sFolder)
    If dDate_ > dDate Then
        dDate = dDate_
        sFile = sFile_
    End If
Next
WScript.Echo "Most recent file: """ & sFile & """"
WScript.Echo "File date: " &dDate
Sub ProcessFolder(sFldr)
    If LTrim(sFldr) = "" Then Exit Sub
    WScript.Echo "Processing """ & sFldr & """"
    For Each oFile In oFSO.GetFolder(sFldr).Files
        If oFile.DateLastModified > dDate_ Then
            dDate_ = oFile.DateLastModified
            sFile_ = oFile.Path
        End if
    Next
    For Each oFolder In oFSO.GetFolder(sFldr).SubFolders
        ProcessFolder(oFolder.path)
    Next
End sub

Similar Messages

  • How to pickup files from multiple directories

    Hi all,
    How to pickup files from multiple directories and send it to two different folders at target
    Ex:
    files\xi\us\US.txt
    files\xi\uk\UK.txt
    i need to pick up the above mentioned two files and send it to the following paths
    app1\files\us\download\US.txt
    app1\files\uk\download\UK.txt
    US.txt has to goto US folder and UK.txt has to goto UK folder only
    Regards

    Hi,
    To pick form multiple folders, select Advanced Mode for file selection in file adapter..
    there u can specify directory name/file names
    Refer
    /people/mickael.huchet/blog/2006/09/18/xipi-how-to-exclude-files-in-a-sender-file-adapter
    To put those files at multiple folders write a command line arguments for this.. go through this weblog...
    /people/michal.krawczyk2/blog/2005/08/17/xi-operation-system-command--error-catching
    XI/PI: Command line sample functions
    /people/michal.krawczyk2/blog/2007/02/08/xipi-command-line-sample-functions
    Hope this will help you....
    Regds,
    Pinangshuk.

  • FILES FROM MULTIPLE DIRECTORIES

    Hi Experts,
                    I got a doubt here plz clarify it
        1.How can we pick files from multiple directories ? and all the files will have different  names?
                    Plz clarify this, good explanations willbe rewarded .
                                                                                    Regards,
                                                                                    Vinod.

    Hi Vinod Reddy,
    One way that i know to solve this prob is by using the 'File Name Masking'.
    This can be done with the sender channel, where you have to specify the
    source directory as <NOTHING>
    source file as <NOTHING>
    This gives you an advanced selection option, where you need to give the Source Directories along with the File name masks (the source files).
    Hope this may solve your problem.
    regards
    vinod v
    reward me if its helpful.

  • Picking up files from multiple directories

    Hi All
    We have scenario where each sore has its one folder with all the files in the folder, now there is about 200 stores so and about 30 interfaces that picks up files from those directories. It's gonna take some time to add al the directories to all 30 interfaces. Is there an easier way to do this?
    Regards

    >
    stephan claassen wrote:
    > Hi
    >
    > Thx for reply
    >
    > abhishek salvi what do mean by ServerName/*? we only have the IP.
    > If I put in /SAPXI/METSAPXI/* it sais:  A file or directory in the path name does not exist
    >
    > Regards
    Suppose you have one File Server installed (say SAP).....it has only two sub-folders (say XI and PI)....now you want to pick files from both the sub-folders....so you can try SAP/* ........
    Please open your File Server location and any sub-folder within it and check if it is / or \ .....and then use the slash (/ or \) accordingly ......if you have IP and no name then give the IP.....rest logic remains the same....
    Regards,
    Abhishek.

  • How to pick files from multiple directories via Sender File Adapter?

    Hi guys,
    I have a scenario File to IDOC. The Sender File Adapter has to take all files: .xml from Source directory E://Current/.
    Actually directories are like
    E:/Plant1/Current/
    E:/Plant1/History/
    E:/Plant2/Current/
    E:/Plant2/History/.
    Can I have one Sender File Adapter to pick all *.xml files
    from
    E:/Plant1/Current/ and
    E:/Plant2/Current/  and how can I write it in Source Directory of Communication Channel?
    Or do I have to have a Sender File Adapter for each Plant?
    Any suggestion please?
    Kind regards,
    Danijela Zivanovic

    Hey
    You might wanna have a look at "Additional selection for source file" parameter in sender file adapter.
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/xi/singleSenderFileCC4MultipleDirectories
    XI/PI: how to exclude files in a sender File adapter?
    Even though this method works but there are some constraints,please check help.sap.com for constraints.
    Thanx
    Aamir

  • Multiple source files from multiple directories in sender CC

    Dear all,
    My requirrement is that ,I need to use multiple directories in sender CC (only one) and send the files to receivers.
    Kindly let me know how it can be done.
    Thanks,
    Srinivasa

    Hi,
    under advanced tab.............If you set the Enable indicator, you can enter variables for the Target Directory and File Name Scheme. Enter the names of the variables and references in the table.
    &#9679;      Enter each variable that you reference in the Target Directory and File Name Scheme fields without the surrounding percentage sign under Name of Variables in the table.
    The variables can refer to attributes of the message header or elements of the message payload.
    &#9675;       If the variables are to refer to an attribute of the message header, add the prefix message: to the name of the variable under Reference. You can specify the following attributes of the message header:
    sender_party, sender_service, receiver_party, receiver_service, interface_name, interface_namespace,
    message_id (message ID with hyphens, for example 9fbe1ff1-9a0d-11d9-8665-cbf10a126331)
    message_id_hex (message ID in hexadecimal format, for example 9fbe1ff19a0d11d98665cbf10a126331)
    For example, if you want to specify the interface name from the message header in the target directory or in the file name scheme, enter message:interface_name as the reference.
    If one of the message attributes contains characters that are not permitted in a file name, for example \, /, :, *, ?, ", <, >, |, then these characters are replaced by an underscore ("_").
    &#9675;       If the variable refers to an element in XML schema, add the prefix payload: to the information under Reference. The reference then comprises a pseudo path description in the form of a comma-separated list with the schema namea,na,nameb,nb,....
    namea,nameb,...corresponds to the element name and na,nb,... corresponds to the occurrence of the element name at the respective level in the document.
    The description begins at the root of the document and ends at the respective element.
    To reference the element that is in bold in the example, the following expression is used: payload:root,1,e1,1,e2,2
    The parser searches for the first occurrence of the root element at the first level. It then searches for the first occurrence of e1 at the second level and for the second occurrence of e2 at the third level. The content of the last element (&#8220;Example Value&#8221;) is set as the value for a specified variable.
    Thanks,
    Madhu

  • File Adapter: picking files from multiple directories

    Hi all,
    In a sender file communication channel with Transport
    Protocol FTP, There are 2 parameters for Picking up the file
    called Source Directory and Filename. If I want to pick the
    files from 2 or more directories, What needs to be done.
    Or is it possible to do so ?
    Without making duplicate interfaces what else can be done ?
    Regards,
    Vijay

    Actually it is possible to select files from different folders for sender channel. It is available with SP14.
    I just copy following description from help.sap.com
    Advanced Selection for Source File
    If you want to set an exclusion mask for the File Name specified above, or if you want to specify multiple directories using a file name mask and exclusion mask, set the Advanced Selection for Source File indicator.
    ¡        Specify an Exclusion Mask for the file name specified above.
    Example
    You want to process all files that have the extension '.txt', but want to exclude all files that begin with the letter 'a'. To do this, enter .txt for File Name, and a for Exclusion Mask.
    ¡        You can enter additional specifications for source directories, file names, and exclusion masks in the table. This data is processed in addition to the details specified above.

  • Read files from multiple directories

    Hy to all! I have a little problem with reading files from a hierarchy of directories,something like this: directory A contains: 4 filed and directory B, and also B contains 3 files and 2 directories and so on. i want to make a method that reads all the files from directory A (including all files from subdirectory). I know i have to use recursive programming, i need a method that will be use to do this. Can U help me to do this????? Thank you all.

    Can U help me to do this?Sure. First, review basic File IO in Java: [http://java.sun.com/docs/books/tutorial/essential/io/file.html]
    Second, have a look at the numerous examples available on the Internet: [http://www.google.com/search?q=java+traverse+directory]
    Third, let us know if you run into any specific problems.
    Good luck!

  • [SOLVED]Copying multiple files from multiple directories to one folder

    Title says it all.  I have a discography folder with subfolders of the different years and albums of a band each containing music, some also have more sub folders.  What I want to do is copy all of the music (.mp3's) from all the folders and sub folders into just one music folder.  I found a find and -exec cp command before but it did absolutely nothing for whatever reason.  Perhaps I did it wrong.  Can anyone help me?
    Thanks
    Last edited by SiegeMachine (2009-11-15 06:54:40)

    . refers to the directory to search (the current directory), it's not a pattern - here's what you want:
    find . -iname '*.mp3' -type f -exec cp {} target_dir/ \;
    This is assuming you're in the music directory - if not, you want
    find /path/to/music -iname '*.mp3' -type f -exec cp {} target_dir/ \;
    Last edited by Pox (2009-11-15 06:53:59)

  • Retrive files from multiple source directories

    Hi,
      I need to retrive diffirent formet files from multiple directories and based on file name I need to send it to destination folders. Can anybody suggest me How can I impliment this interface.
    Thanks & Regards
    VenkatK

    Venkat,
    I hope since you are taking different format files, you are not doing any mapping. You are moving from one location to another location, because if you different formats then you can do in one mapping your requirement.
    If it is correct then as shabharish mentioned you can pick the files using multiple file sender adapters. With this you can pick the files, but to send to different directories enable ASMA in sender file commkunication channel. Then in receiver communication check the extension for each format and then give the directory name so that it routes to the destination you mentioned.
    Regards,
    ---Satish

  • Capturing log files from multiple .ps1 scripts called from within a .bat file

    I am trying to invoke multiple instances of a powershell script and capture individual log files from each of them. I can start the multiple instances by calling 'start powershell' several times, but am unable to capture logging. If I use 'call powershell'
    I can capture the log files, but the batch file won't continue until that current 'call powershell' has completed.
    ie.  within Test.bat
    start powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > a.log 2>&1
    timeout /t 60
    start powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > b.log 2>&1
    timeout /t 60
    start powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > c.log 2>&1
    timeout /t 60
    start powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > d.log 2>&1
    timeout /t 60
    start powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > e.log 2>&1
    timeout /t 60
    start powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > f.log 2>&1
    the log files get created but are empty.  If I invoke 'call' instead of start I get the log data, but I need them to run in parallel, not sequentially.
    call powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > a.log 2>&1
    timeout /t 60
    call powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > b.log 2>&1
    timeout /t 60
    call powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > c.log 2>&1
    timeout /t 60
    call powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > d.log 2>&1
    timeout /t 60call powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > e.log 2>&1
    Any suggestions of how to get this to work?

    Batch files are sequential by design (batch up a bunch of statements and execute them). Call doesn't run in a different process, so when you use it the batch file waits for it to exit. From CALL:
    Calls one batch program from another without stopping the parent batch program
    I was hoping for the documentation to say the batch file waits for CALL to return, but this is as close as it gets.
    Start(.exe), "Starts a separate window to run a specified program or command". The reason it runs in parallel is once it starts the target application start.exe ends and the batch file continues. It has no idea about the powershell.exe process
    that you kicked off. Because of this reason, you can't pipe the output.
    Update: I was wrong, you can totally redirect the output of what you run with start.exe.
    How about instead of running a batch file you run a PowerShell script? You can run script blocks or call individual scripts in parallel with the
    Start-Job cmdlet.
    You can monitor the jobs and when they complete, pipe them to
    Receive-Job to see their output. 
    For example:
    $sb = {
    Write-Output "Hello"
    Sleep -seconds 10
    Write-Output "Goodbye"
    Start-Job -Scriptblock $sb
    Start-Job -Scriptblock $sb
    Here's a script that runs the scriptblock $sb. The script block outputs the text "Hello", waits for 10 seconds, and then outputs the text "Goodbye"
    Then it starts two jobs (in this case I'm running the same script block)
    When you run this you receive this for output:
    PS> $sb = {
    >> Write-Output "Hello"
    >> Sleep -Seconds 10
    >> Write-Output "Goodbye"
    >> }
    >>
    PS> Start-Job -Scriptblock $sb
    Id Name State HasMoreData Location Command
    1 Job1 Running True localhost ...
    PS> Start-Job -Scriptblock $sb
    Id Name State HasMoreData Location Command
    3 Job3 Running True localhost ...
    PS>
    When you run Start-Job it will execute your script or scriptblock in a new process and continue to the next line in the script.
    You can see the jobs with
    Get-Job:
    PS> Get-Job
    Id Name State HasMoreData Location Command
    1 Job1 Running True localhost ...
    3 Job3 Running True localhost ...
    OK, that's great. But we need to know when the job's done. The Job's Status property will tell us this (we're looking for a status of "Completed"), we can build a loop and check:
    $Completed = $false
    while (!$Completed) {
    # get all the jobs that haven't yet completed
    $jobs = Get-Job | where {$_.State.ToString() -ne "Completed"} # if Get-Job doesn't return any jobs (i.e. they are all completed)
    if ($jobs -eq $null) {
    $Completed=$true
    } # otherwise update the screen
    else {
    Write-Output "Waiting for $($jobs.Count) jobs"
    sleep -s 1
    This will output something like this:
    Waiting for 2 jobs
    Waiting for 2 jobs
    Waiting for 2 jobs
    Waiting for 2 jobs
    Waiting for 2 jobs
    Waiting for 2 jobs
    Waiting for 2 jobs
    Waiting for 2 jobs
    Waiting for 2 jobs
    Waiting for 2 jobs
    When it's done, we can see the jobs have completed:
    PS> Get-Job
    Id Name State HasMoreData Location Command
    1 Job1 Completed True localhost ...
    3 Job3 Completed True localhost ...
    PS>
    Now at this point we could pipe the jobs to Receive-Job:
    PS> Get-Job | Receive-Job
    Hello
    Goodbye
    Hello
    Goodbye
    PS>
    But as you can see it's not obvious which script is which. In your real scripts you could include some identifiers to distinguish them.
    Another way would be to grab the output of each job one at a time:
    foreach ($job in $jobs) {
    $job | Receive-Job
    If you store the output in a variable or save to a log file with Out-File. The trick is matching up the jobs to the output. Something like this may work:
    $a_sb = {
    Write-Output "Hello A"
    Sleep -Seconds 10
    Write-Output "Goodbye A"
    $b_sb = {
    Write-Output "Hello B"
    Sleep -Seconds 5
    Write-Output "Goodbye B"
    $job = Start-Job -Scriptblock $a_sb
    $a_log = $job.Name
    $job = Start-Job -Scriptblock $b_sb
    $b_log = $job.Name
    $Completed = $false
    while (!$Completed) {
    $jobs = Get-Job | where {$_.State.ToString() -ne "Completed"}
    if ($jobs -eq $null) {
    $Completed=$true
    else {
    Write-Output "Waiting for $($jobs.Count) jobs"
    sleep -s 1
    Get-Job | where {$_.Name -eq $a_log} | Receive-Job | Out-File .\a.log
    Get-Job | where {$_.Name -eq $b_log} | Receive-Job | Out-File .\b.log
    If you check out the folder you'll see the log files, and they contain the script contents:
    PS> dir *.log
    Directory: C:\Users\jwarren
    Mode LastWriteTime Length Name
    -a--- 1/15/2014 7:53 PM 42 a.log
    -a--- 1/15/2014 7:53 PM 42 b.log
    PS> Get-Content .\a.log
    Hello A
    Goodbye A
    PS> Get-Content .\b.log
    Hello B
    Goodbye B
    PS>
    The trouble though is you won't get a log file until the job has completed. If you use your log files to monitor progress this may not be suitable.
    Jason Warren
    @jaspnwarren
    jasonwarren.ca
    habaneroconsulting.com/Insights

  • How to get rid of Index of file:///C:/Users/lago/AppData/Roaming/SpecialSavings/ Up to higher level directory Name Size Last Modified File:SpecialSavings_2.0

    I am unable to uninstall this high risk addon shown below in Firefox Ad Data
    Index of file:///C:/Users/lago/AppData/Roaming/SpecialSavings/
    Up to higher level directory
    Name Size Last Modified
    File:SpecialSavings_2.0.0.crx 25 KB 19-Aug-12 6:03:42 PM
    Anyone know how to get rid of it please?

    I am unable to uninstall this high risk addon shown below in Firefox Ad Data
    Index of file:///C:/Users/lago/AppData/Roaming/SpecialSavings/
    Up to higher level directory
    Name Size Last Modified
    File:SpecialSavings_2.0.0.crx 25 KB 19-Aug-12 6:03:42 PM
    Anyone know how to get rid of it please?

  • Call and display Xcelsius SWF file from an SAP Transaction

    Hello Experts ,
                          Could you please suggest if it is possible to Call and display Xcelsius SWF file
    from an SAP Transaction and if Yes how can this be achieved.
    Regards ,
    Jerin.

    Jerin,
    It is possible to embed a Xcelsius model into an SAP WebTemplate (Anil promised to write a blog about this very soon). After that you can include the WebTemplate in the GUI menu, Role menu or Portal.
    Henk.

  • 'No Upload Authorization' While Uploading a Text File from Multiple Select

    Hi all,
       The User is trying to upload a text file from Multiple Selection screen of a Query in BEx and it gives the error message of 'No Upload Authorization' (Error DB886).
       In 'Logon data' tab of Tcode SU01, it has 'User' for 'User Group for Authorization check' for this User.
       I could upload a text file from Multiple Selection screen with my User Id.
       An idea about this error, PLEASE ?
    Thanks,
    Venkat.

    Hi Ron,
       This User does not have the access to Tcode ST01.
       The user executed Tcode SU53 immediately following the authorization failure to see the authorization objects. The 'Authorization obj' is blank and under the Description it has 'The last Authorization check was successful' with green tick mark.
      Any further suggestions, PLEASE.
    Thanks.

  • Creating an XML file from multiple sql tables

    I have very little xml experience, but need to generate an xml file from multiple table. I know what the output needs to look like, but do not know how to setup the code. Any help would be appreciated.
    - <Practice SourceID="EPIC" ExternalPracticeID="PPAWB">
    - <Provider ExternalProviderID="TB2" FirstName="THOMAS G" LastName="BREWSTER">
    - <Patient ExternalPatientID="99999" OldExternalPatID="" FirstName="test" MiddleName="J" LastName="test" Gender="M" DateOfBirth="2005-08-12" SocSecNumber="000-00-0000" LanguageID="22" AddressOne="test" AddressTwo="" City="test" StateID="20" ZipCode="99999" DayPhone="" EveningPhone="207-999-9999" StatusID="">
    <Measure MeasureID="2" MeasureValue="5" MeasureDate="2008-10-24 13:43:00" />
    <Measure MeasureID="2" MeasureValue="5" MeasureDate="2008-10-24 14:23:00" />
    <Measure MeasureID="3" MeasureValue="1" MeasureDate="2008-10-24 13:43:00" />
    <Measure MeasureID="3" MeasureValue="1" MeasureDate="2008-10-24 14:23:00" />
    <Measure MeasureID="32" MeasureValue="3" MeasureDate="2008-10-24 13:51:00" />
    <Measure MeasureID="33" MeasureValue="1" MeasureDate="2008-10-24 13:43:00" />
    <Measure MeasureID="33" MeasureValue="1" MeasureDate="2009-02-09 10:09:00" />
    <Measure MeasureID="4" MeasureValue="5" MeasureDate="2008-10-24 13:43:00" />
    <Measure MeasureID="4" MeasureValue="5" MeasureDate="2008-10-24 14:23:00" />
    <Measure MeasureID="40" MeasureValue="2008-10-24 13:43:00" MeasureDate="2008-10-24 13:43:00" />
    <Measure MeasureID="40" MeasureValue="2008-10-24 14:23:00" MeasureDate="2008-10-24 14:23:00" />
    <Measure MeasureID="41" MeasureValue="2008-10-24 13:43:00" MeasureDate="2008-10-24 13:43:00" />
    <Measure MeasureID="41" MeasureValue="2008-10-24 13:51:00" MeasureDate="2008-10-24 13:51:00" />
    </Patient>
    </Provider>
    </Practice>

    You are interested in XMLElement and probably XMLAgg. Since you didn't list a version, I can't provide links to the corresponding documentation. I cringe at all the attributes on the Patient element as that info should really be elements.
    To create the Measure node, your overall SQL statement may look something like (not tested)
    SELECT XMLElement....
              XMLAgg(SELECT XMLElement
                       FROM measures_table
                      WHERE join condition to parent)
      FROM patient,
           provider,
           practice
    WHERE join conditionsFor additional help, please include your version (4 digits), some sample data, and what you have tried.

Maybe you are looking for

  • Content Barrier Problems

    Content Barrier will not let me open gmail, no matter how i set its preferences. Does anyone know if this is a bug, or how to fix it?

  • What is the best way to use Berkeley DB, C or C++ interface ?

    Hello, I'm using C++ interface but much samples, solutions and utils are in C. What is the best way to use Berkeley DB, C or C++ interface ? Lets talk a little about this...which is the interface you prefer and why ? Thanks DelNeto

  • ECM question

    We are using the Enterprise Compensation Management (ECC 5.0) and I am not able to get the defualt guidelines when running the report by transaction PECM_CREATE_COMP_PRO. I have set the Eligibility and Guidelines correctly as I am able to do thru PA3

  • Upgrade DCM9901 cannot get the config with upgrade it

    Dear all, I  want to upgrade a DCM 9901 in version 12.10.03 and my problem appears  when I launch Upgrade it, the DCM is detected but I have an error  message : "Cannot get aconfig.txt or bconfig.txt from the target". So I can't upgrade the equipment

  • Meter removal date the same as estimated reading

    meter removal date is the same as date of estiamated reading, but readings are not the same. system does not take into account removal reading (22) Example: meter (XXX) reason 22 RR 01 date 20.01.2011 reading 1000 meter (XXX) reason 01 RR 03 date 20.