windows - Date modified of most recent file(s) in a set of sub-directories -


i need assistance in creating output file (or 'report') based on bunch of sub-folders. want email report myself nightly (i can handle emailing of file, not sure how create actual file).

my data structure:

  • main working directory containing:
    • my .bat file copies data 3 servers tfx logs folder below
    • tfx logs folder
      • client folder(s)
        • up 15 days of .log files

what want do:

  1. copy data 3 servers tfx log folder, maintaining structure (tfx log\client\tfx_*.log) (completed)
  2. create single .txt or .csv file list of newest tfx_*.log files each client folder (just newest - not 15 files there). this:

    directory name | file name | date modified

  3. email file myself (completed)

i need number 2.

this have far:

:: copying data  xcopy "%source1%" "%destination%\tfx logs\" /s /y xcopy "%source2%" "%destination%\tfx logs\" /s /y  xcopy "%source3%" "%destination%\tfx logs\" /s /y   :: deleting old output file before creating new 1  del "%destination%\*.txt"  :: creating new output file  powershell "& '%destination%\listfiles.ps1'"  ren "%destination%\importreport.txt" importreport_%tday%.txt 

my powershell script looks this:

get-childitem "..daily report\tfx logs\" -recurse -file | where{$_.lastwritetime -gt (get-date).adddays(-1)} | out-file "..daily report\importreport.txt" 

what right this:

(i want latest file each folder using structure specified above in #2 if possible)

    directory: ..\tfx logs\client1   mode                lastwritetime     length name                               ----                -------------     ------ ----                               -a---         4/22/2015   3:06        329 tfx_db21_1522040304.log              directory: ..\tfx logs\client2   mode                lastwritetime     length name                               ----                -------------     ------ ----                               -a---         4/22/2015  12:22        331 tfx_db4_1522040017.log               directory: ..\tfx logs\client3   mode                lastwritetime     length name                               ----                -------------     ------ ----                               -a---         4/21/2015   8:03 pm        329 tfx_db4_1521042002.log   

cliff's notes:

i want rearrange output powershell be:

directory name (directory) | file name (name) | last modified date (lastwritetime)

without other stuff , of white space. nice row row output.

also, if possible, if there blank folder in there (or there folder files older 15 days), still show in report file, no records. way i'll know that, hey, client hasn't ran in while , needs examined sure.

update 4/29/15

magoo's suggestion below showed promise hasn't worked me. doesn't anything. have other ideas of how improve upon have?

@echo off setlocal set "source1=u:\sourcedir" set "source2=u:\sourcedir2" set "source3=u:\source dir3" set "destdir=u:\destdir"  del "%destdir%\*.txt" %%d in ("%source1%" "%source2%" "%source3%" ) call :process %%d  goto :eof  :process echo(xcopy %1 "%destdir%\tfx logs\" /s /y pushd %1 /f %%a in ('dir /b /o-d tfx_*.log') >>"%destdir%\importreport_%tday%.txt" (  echo %~1,%%~ta,%%~za,%%a  popd  goto :eof ) popd goto :eof 

this should solve problem.

for testing, used u: drive , destdir destination diectoryname.

simply delete destination .txt files, list of directory names, call process which

  • copies logfiles required xcopy commands merely echoed testing purposes. after you've verified commands correct, change echo(xcopy xcopy copy files. append >nul suppress report messages (eg. 1 file copied)

  • switches target directory

  • performs directory-list basic format of files matching mask, sorted in reverse-date order
  • outputs directory name, filetime. filesize , name report file (i'll assume you've set tday)
  • pops original directory , terminates loop 1 filename (the last chronologically) reported.

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -