1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

filecheckdate

Posted at
title.rb

@echo off
setlocal enabledelayedexpansion

set "FTP_SUCCESS_CNT=0"
set "FTP_FAIL_CNT=0"
set "FTP_FILE_CNT=0"
set "DEF_DIR=C:\FT\JO\DEF\file_check_target.txt"
set "TEMP_DIR=C:\FT\JO\DEF\temp_files.txt"
set "PERIOD_DAY=3"

:: Clear the temporary file
> "!TEMP_DIR!" echo.

:: Iterate through each folder in the DEF_DIR file
for /f "delims=" %%d in (%DEF_DIR%) do (
    set "folder=%%d"
    echo Checking folder: "!folder!"
    
    if exist "!folder!" (
        echo Found folder: "!folder!"
        
        :: Use forfiles to find files from three days ago
        forfiles /P "!folder!" /D -%PERIOD_DAY% /C "cmd /c echo @path" >> "!TEMP_DIR!"

        :: Check if any files were output to the temporary file
        if exist "!TEMP_DIR!" (
            echo Files found in "!folder!":
            :: Iterate through found files
            for /f "delims=" %%f in (!TEMP_DIR!) do (
                set "file_path=%%~f"
                echo Processing file: "!file_path!"
                set /a "FTP_FILE_CNT+=1"

                :: Output the file content
                echo File content:
                type "!file_path!"
                echo.

                :: Read the last line of the file
                set "last_line="
                for /f "delims=" %%l in ('type "!file_path!"') do (
                    set "last_line=%%l"
                )

                if defined last_line (
                    set "last_char=!last_line:~-1!"
                    if "!last_char!"=="$" (
                        set /a "FTP_SUCCESS_CNT+=1"
                    ) else (
                        set /a "FTP_FAIL_CNT+=1"
                    )
                ) else (
                    echo File "!file_path!" is empty.
                    set /a "FTP_FAIL_CNT+=1"
                )
            )
        ) else (
            echo No files found in "!folder!".
        )
    ) else (
        echo Folder "!folder!" does not exist.
    )
)

:: Print the results
echo.
echo Succeeded: %FTP_SUCCESS_CNT%
echo Failed: %FTP_FAIL_CNT%
echo Total Files: %FTP_FILE_CNT%

endlocal


1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?