Answer the question
In order to leave comments, you need to log in
Create a check to see if files or folders exist in a specific directory?
Help write a script, check the existence of files or folders in a folder, as well as check the modification dates of these files and folders.
There is a service that creates files over time and then collects them in the -C:\Papka folder, but sometimes the service falls off, you need to create a check for bat, at startup, check if there are files and folders in the C:\Papka folder, check the modification date and if it is later than 4 hours, delete everything in the C:\Papka folder.
Couldn't find anything useful.
Answer the question
In order to leave comments, you need to log in
Checking the file like this:
@echo off
:loop
if not exist "c:\Papka\somefile" Goto Loop
echo "finish"
I'll start from the end: cmd does not support working with dates in any form.
You can get the file's last modified date, but it will be a textual date. Next, you need to manually select all the components of the date and, using the meager possibilities of set / a and a heap of if, calculate whether it was later than 4 hours or not. You can do it, but it will be ... "not technologically advanced" :-)
At one time I wrote a bat script that converts a date into a timestamp and vice versa. I can search if you're interested.
I would suggest you use powershell script, vbs, js - they all know how to work with dates. Implementing your task on them is quite simple.
Checking the existence of files and subfolders in a given folder:
set "indir=c:\papka"
:: Проверка существования файлов:
for /f "tokens=* delims=" %%a in ('dir /b /a-d "%indir%\*" ') do (
echo.Есть файл: %%~fa
)
:: Проверка существования каталогов:
for /f "tokens=* delims=" %%a in ('dir /b /ad "%indir%\*" ') do (
echo.Есть каталог: %%~fa
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question