China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 11:25
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to write such a batch processing? View 1,617 Replies 3
Original Poster Posted 2004-12-15 00:00 ·  中国 宁夏 银川 电信
初级用户
Credits 118
Posts 5
Joined 2004-08-17 00:00
21-year member
UID 30273
Gender Male
Status Offline
System: adv win2k
Goal to achieve: Synchronize files between two computers in the local area network. Then run the synchronized files.
There is a file xxx.exe in directory aaa on Computer A and it is shared.
Computer B can log in to Computer A (with username and password).
There is a file xxx.exe in directory BBB on Computer B.
Problem:
Now automatic login to Computer A has been achieved on Computer B and the shared directory is mapped as a drive letter R: on Computer B.
Now we want to perform copy if the file on Computer A is different from the file on local Computer B (just different dates are okay, and also copy if the file does not exist locally, both are xxx.exe). After copying, execute xxx.exe.
Now only a batch file is missing.
If there is a batch file, it can be combined with Windows scheduled tasks for full automation.
Which gentleman can write the batch file. Thanks in advance.
Can fc and comp be used! Please write the batch file. ------------
------------
Now it is achieved that the date of the file can be displayed using the statement for. That is, use for /f "skip=3" %a IN ('dir e:\a\xxx.exe' do @if exist %a echo %~ta
But how to compare. But I write these commands in the batch file and they are not correct. Who knows.
Always getting errors. But it is normal in the command line.
Depressed~~~
Floor 2 Posted 2004-12-16 00:00 ·  中国 宁夏 银川 电信
初级用户
Credits 118
Posts 5
Joined 2004-08-17 00:00
21-year member
UID 30273
Gender Male
Status Offline
Keep up the good work. I finally succeeded.
Just why can't it be executed in the batch file.
It can be done in the command line. Why is that.
@echo off
if EXIST xxx.exe goto cmp
xcopy r:\aaa\xxx.exe
:cmp
for /f "skip=3" %%a IN ('dir r:\aaa\xxx.exe' do @if exist %%a set var1=%%~ta
for /f "skip=3" %%a IN ('dir xxx.exe' do @if exist %%a set var2=%%~ta
if %var1%==%var2% do goto end
copy r:\aaa\xxx.exe /yy
xxx.exe
:end
----------------
How can the if be used because there are spaces in var1.


Floor 3 Posted 2004-12-16 00:00 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re: Expression:
  To solve the space problem of var, you can add quotes on both sides of var1 and var2, just like
if "%var1%"=="%var2%" do goto end
This method is not applicable to win9x/dos6.xx (under its environment, you need to first output to a file, then use fc+find to judge).
Also: The do in your statement seems redundant. Try changing it to the following form:
if "%var1%"=="%var2%" goto end
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 4 Posted 2004-12-17 00:00 ·  中国 宁夏 银川 电信
初级用户
Credits 118
Posts 5
Joined 2004-08-17 00:00
21-year member
UID 30273
Gender Male
Status Offline
Thanks to the person above. I'm really stupid myself
Forum Jump: