Last active
December 11, 2015 09:39
-
-
Save davetromp/4581618 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: This script checks a files size | |
:: If it is less then a certain size, it will be switched by a previous | |
:: version of the file. If the filesize is OK it will be copied to a backup location. | |
setlocal | |
:: location of the file | |
set dir=D:\import | |
:: location of an older version (backup) of the file | |
set olddir=D:\import-previous | |
:: name of the file | |
set file=%dir%\importfile.csv | |
:: name of the old file | |
set oldfile=%olddir%\importfile.csv | |
:: log file detail | |
echo ----------------------------------- >> filesize.txt | |
date /t >> filesize.txt | |
dir %file% | find "importfile.csv" >> filesize.txt | |
:: Get and set the file size in bytes of new file | |
for %%a in (%file%) do ( | |
set length=%%~za | |
) | |
:: check if it is less then 100 bytes | |
if %length% LSS 100 ( | |
set msg=File is to small - replacing it with the old file | |
:: delete the new too small file | |
del %file% | |
:: copy the old file to file location | |
copy %oldfile% %file% | |
) else ( | |
set msg=Filesize OK - Copying it to backup | |
:: delete the old backup file | |
del %oldfile% | |
:: copy the new file to the backup location | |
copy %file% %oldfile% | |
) | |
echo %msg% >> filesize.txt | |
endlocal | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment