When I open a command prompt window and run each of the lines it does exactly what I want it to do.
-Variable(mm) assigned to current time minutes
-Variable (ff)assigned to File time minutes
- Variable(cc) assigned to current time minutes minus File time Minutes
-If CC is greater than 10 then I have an error
However when I create a '.cmd' file and run it get the error "~ta was unexpected at this time."on the highlighted line below.
echo on
cd..
cd workdir\CUSTDCHECK
IF NOT EXIST P:\Gensrvnt\workdir\CUSTDCHECK\o_100_00000000* GOTO end
REM GET CURRENT TIME(MINUTES only!!)
set mm=%time:~3,-6%
REM get date time of files in folder &REM GET FILE TIME( IN MINUTES!!)
for %a in (*.*) do set FileDate=%~ta
set ff=%filedate:~14%
REM Calculate the difference between minutes of current time minus minutes of the file
set /a cc= %mm%-%ff%
REM if difference is more than 10 then we have an error.
if /i %cc% GTR 10 (echo Error) ELSE echo no error
:end
echo this is the end my friend!
I would greatly appreciate some help on this?
For loop runs in command prompt screen but not in cmd file??
Moderator: DosItHelp
Re: For loop runs in command prompt screen but not in cmd fi
use for %%a in (*.*) do set FileDate=%%~ta
Re: For loop runs in command prompt screen but not in cmd fi
foxidrive wrote:use for %%a in (*.*) do set FileDate=%%~ta
Foxi to the rescue (as always)
thanks again kind sir
Re: For loop runs in command prompt screen but not in cmd fi
Reading is FUN!
H:\>for /?
Runs a specified command for each file in a set of files.
FOR %variable IN (set) DO command [command-parameters]
%variable Specifies a single letter replaceable parameter.
(set) Specifies a set of one or more files. Wildcards may be used.
command Specifies the command to carry out for each file.
command-parameters
Specifies parameters or switches for the specified command.
To use the FOR command in a batch program, specify %%variable instead
of %variable. Variable names are case sensitive, so %i is different
from %I.
Re: For loop runs in command prompt screen but not in cmd fi
for %%a in (*.*) do set FileDate=%%~ta
How do I just get the oldest file in the folder and only use that time.
(Squeezeman) - I have read for/? and nothing jumps out at me that can carry this out.
There is nothing in the FIND command that does it by oldest file either which was another thought
There is a DIR command that can output the oldest . DIR /O:D
How do I just get the oldest file in the folder and only use that time.
(Squeezeman) - I have read for/? and nothing jumps out at me that can carry this out.
There is nothing in the FIND command that does it by oldest file either which was another thought
There is a DIR command that can output the oldest . DIR /O:D
Re: For loop runs in command prompt screen but not in cmd fi
This is meant to go through the list of files and remember the oldest one.
Code: Select all
@echo off
for /f "delims=" %%a in (' dir /b /a-d /o:-d ') do set "olddate=%%~ta"