0

I have 2 plain text files, one on the local PC and another on the server. (The files only store the release date, e.g. 02/02/2018).

I want to write a to check if the text file on the server is a newer date than the date on the users machine and download the new files from server based on this.

I have used and it works fine, but the concern is to maintain the newer set of files.

Please advise if this is achievable.

Compo
  • 36,585
  • 5
  • 27
  • 39
  • 1
    If you would like us to help you with your code, you need to provide us with an opportunity to read it. You should also fully explain what your specific issue is with using [tag:fc]. Please [edit your question](https://stackoverflow.com/posts/55934933/edit) to include the code, _(properly formatted using the **`{}`** button)_, and necessary explanation; thank you. – Compo May 01 '19 at 10:52
  • a simple way if the file on the server will always be either the same, or later date than the ones on the PC's is to use `comp` or `fc` and use `errorlevel` to determine if the file contents are different.. `comp file1.txt file2.txt /M>nul` then `if not %errorlevel% equ 0 echo do something` – Gerhard May 01 '19 at 11:06
  • 1
    `If ErrorLevel 1` would be my preference over `if not %errorlevel% equ 0`. – Compo May 01 '19 at 11:15
  • Are you looking to compare that date OF the files (ie. the date the files were created) or the date contained IN the files? Please also specify the date-format of interest in the latter case. – Magoo May 02 '19 at 03:57
  • Hi Magoo.....Its the date contained IN the files.The content of the file is nothing but a date...like 02/02/2018. – zainab.july2019 May 02 '19 at 05:25
  • Did you see my comment at all? – Gerhard May 02 '19 at 06:16
  • @zainab.july2019, your example date isn't much use to us unless you explain which is the month and which is the day! – Compo May 02 '19 at 20:16

1 Answers1

0

Your sample date is ambiguous.

To compare a date (without converting to datetime type or serial) you need to order it by yyyy,MM,dd.

What is your 02/02/2018 meant to be MM/dd/yyyy? Or dd/MM/yyyy?

:: Q:\Test\2019\05\02\SO_55934933.cmd
@Echo off
Call :GetDate Srv "\\server\share\folder\file.txt"
Call :GetDate PC  "X:\folder\file.txt"

if not defined Srv (Echo couldn't obtain server date  &pause&Exit /b 1)
if not defined PC  (Echo couldn't obtain local PC date&pause&Exit /b 1)

if %Srv% geq %PC% (
    Echo Server date %Srv% newer or equal to PC date %PC%
) else (
    Echo Server date %Srv% older than PC date %PC%
)
Goto :Eof
:GetDate and reverse order
set /p "Dt="<%2
:: assuming dd/MM/yyyy
For /f "tokens=1-3delims=/" %%D in ("%DT%") Do Set "%1=%%F%%E%%D"
:: assuming dd/MM/yyyy
:: For /f "tokens=1-3delims=/" %%D in ("%DT%") Do Set "%1=%%F%%D%%E"

The batch contains both variants, MM/dd/yyyy is commented out.

Sample output:

> Q:\Test\2019\05\02\SO_55934933.cmd
Server date 20180203 newer or equal to PC date 20180202