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-06-26 18:07
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Asking for Advice] How to Realize File Synchronization Between USB Drive and Computer [Solved] View 2,625 Replies 10
Original Poster Posted 2007-01-06 00:23 ·  中国 湖南 长沙 联通
新手上路
Credits 18
Posts 7
Joined 2007-01-05 23:47
19-year member
UID 75546
Gender Male
Status Offline
I am a clerk. I often need to analyze multiple data tables (sometimes I also need to take them home to work overtime). But sometimes I often forget to copy the files that I have processed on the computer into the USB flash drive, so I often have to run back and forth between the company and home.

Is there any expert who can tell me how to achieve file synchronization between the computer and the USB flash drive, that is, automatically search for specific documents in the computer (because of work reasons, there are sometimes multiple related data tables, so it is best to be able to search for specified extensions), and copy them to the USB flash drive.

Of course, this program preferably runs automatically. For example, double-clicking the USB flash drive or clicking it automatically copies once every 1 minute.

Thank you!

[ Last edited by hover421 on 2007-1-10 at 08:43 AM ]
Floor 2 Posted 2007-01-06 02:08 ·  中国 江西 赣州 电信
高级用户
★★
论坛上抢劫的
Credits 551
Posts 246
Joined 2006-09-21 12:35
19-year member
UID 63270
Status Offline
When working on a computer

start Your program path
:1
sleep 60s
tasklist|findstr /i "Program name">nul && goto succeed ::If you are not clear, you can check it in the Task Manager! Such as QQ.EXE
copy "The file you want to copy" "USB flash drive path"
exit
:succeed
copy "The file you want to copy" "USB flash drive path"
goto 1


The following is put into the root directory of the USB flash drive 1.bat

copy "The file you want to copy" "%cd:~0,1%:\USB flash drive subfolder path"
start explorer "%cd:~0,1%
exit


The following is saved as AutoRun.inf and put into the root directory of the USB flash drive


shellexecute=..\1.bat
Icon=Your picture (in bmp, ico format, etc.)


If you don't want to use sleep 60s, you can replace this sentence with ping 1 -n 1 -w 60000 2>nul 1>nul!!
copy can be replaced by xcopy, such as xcopy "The file you want to copy" "USB flash drive path" /d /y /u This will only copy the files that are in the USB flash drive and newer than those in the USB flash drive!

[ Last edited by lotus516 on 2007-1-6 at 03:10 AM ]
Floor 3 Posted 2007-01-06 02:33 ·  中国 甘肃 甘南藏族自治州 合作市 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Add the bat into autorun.ini
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
+1 2010-04-16 20:07
Floor 4 Posted 2007-01-06 12:32 ·  中国 湖南 长沙 联通
新手上路
Credits 18
Posts 7
Joined 2007-01-05 23:47
19-year member
UID 75546
Gender Male
Status Offline
Thanks everyone, but I still have some questions. First, how to handle the following code? Is it also made into a bat?


When working on the computer
CODE:
--------------------------------------------------------------------------------

start your program path
:1
sleep 60s
tasklist|findstr /i "program name">nul && goto succeed ::If you are not clear, you can check it in the Task Manager! Such as QQ.EXE
copy "the file you want to copy" "USB flash drive path"
exit
:succeed
copy "the file you want to copy" "USB flash drive path"
goto 1


Also, the autorun.inf doesn't seem to work. Is there any other step?

Thanks
Floor 5 Posted 2007-01-07 02:00 ·  中国 江西 赣州 电信
高级用户
★★
论坛上抢劫的
Credits 551
Posts 246
Joined 2006-09-21 12:35
19-year member
UID 63270
Status Offline
Oh, of course, it's to keep the bat file!! The autorun.inf is okay because I copied it from my MP4!!! Mine can all run normally!!! For details about autorun.inf, see http://www.cn-dos.net/forum/viewthread.php?tid=25418&fpage=1&highlight=autorun.inf

[ Last edited by lotus516 on 2007-1-7 at 02:09 AM ]
Floor 6 Posted 2007-01-07 04:53 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
Hehe, this is really a clever idea.
"Lazy Clerk"
Floor 7 Posted 2007-01-07 11:45 ·  中国 湖南 长沙 联通
新手上路
Credits 18
Posts 7
Joined 2007-01-05 23:47
19-year member
UID 75546
Gender Male
Status Offline
When working on the computer
CODE:
--------------------------------------------------------------------------------

start "Your program path"
:1
sleep 60s
tasklist|findstr /i "Program name">nul && goto succeed ::If you are not clear, you can check it in the Task Manager! Such as QQ.EXE
copy "The file you want to copy" "USB flash drive path"
exit
:succeed
copy "The file you want to copy" "USB flash drive path"
goto 1


I'm sorry, I think I made a mistake in expression. I don't want to automatically run a certain program, but I want that when the USB flash drive is double-clicked (this has been solved through autorun.inf, thank you), the computer will automatically help me find the data table files in the computer (because sometimes there are many and messy, so it is best to find by extension), and copy them to my USB flash drive, and it is best to automatically copy again at intervals, I think this will keep the data synchronized, I wonder if this can be done?
Troublesome everyone!
Floor 8 Posted 2007-01-08 10:51 ·  中国 江西 赣州 电信
高级用户
★★
论坛上抢劫的
Credits 551
Posts 246
Joined 2006-09-21 12:35
19-year member
UID 63270
Status Offline
@echo off
echo. >txt.bak
:1
set /p word=Please enter the file extension to back up, if you have finished entering, just press Enter directly:
if "%word%"=="" goto 2
echo %word% >>txt.bak
set word=
goto 1
:2
start explorer %cd:~2%
:3
ping 1 -n 1 -w 60000 2>nul 1>nul
for /f %%i in (txt.bak) do copy "The folder you want to copy\*.%%i" "%cd:~0,1%:\The path of the next level folder of the USB flash drive"
for /f %%i in (txt.bak) do copy "The folder you want to copy\*.%%i" "%cd:~0,1%:\The path of the next level folder of the USB flash drive"
tasklist|findstr /i "Program name">nul && goto 3
exit
Because it needs to monitor your program, so you must do your work within 60 seconds, otherwise it will not automatically back up after 1 minute!!
sorry, accidentally changed echo %word% >>File suffix name to save.txt to echo %word% >>txt.bak
Copy the for sentence several times for multiple folders!!

[ Last edited by lotus516 on 2007-1-9 at 02:25 PM ]
Floor 9 Posted 2007-01-09 03:48 ·  中国 湖南 长沙 联通
新手上路
Credits 18
Posts 7
Joined 2007-01-05 23:47
19-year member
UID 75546
Gender Male
Status Offline
Upstairs, first of all, thank you so much for your enthusiasm. But it seems this code isn't working. It just flashes by. And I still have some questions to ask you.

First of all, is the code you gave in building 8 the same in function as the last two sections of code you gave in building 2? Can they be used separately, or do all three sections of code need to be used together?

Second, your code seems to be able to search only one folder. It would be nice if it could search the entire hard drive. That is to say, can it automatically search for files with the same extension in each directory?

Finally, ask a question unrelated to this request. Can you tell me how to learn DOS? I already know some basic and simplest DOS operations.

Thank you. I'm sorry to trouble you again.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
+1 2010-07-11 18:32
Floor 10 Posted 2007-01-09 14:22 ·  中国 江西 赣州 电信
高级用户
★★
论坛上抢劫的
Credits 551
Posts 246
Joined 2006-09-21 12:35
19-year member
UID 63270
Status Offline
It's not that it's impossible to search the entire disk, it's just that Windows has some backup files by itself, such as *.bak and so on. Doesn't searching the entire disk also back them up? I still only half understand the code for searching the entire disk!!! Also, your data files are on each disk, not placed together? The one on the 8th floor is for the USB flash drive and not used together with the one on the 2nd floor. The one behind the 2nd floor has no real-time update and can replace them!! But there is one point, that is, after running the USB flash drive, it must work!! Otherwise, real-time update cannot be done!! For learning, I learned before, and there are also looking at the posts of experts. Searching is the best teacher, and also Windows has a built-in teacher, ntcmds.chm!!! You can take a look by yourself!! Give one for searching the entire disk, but I don't have time to run it now, I'll run it tomorrow!!
Corrected the error, for searching the entire disk!! Please change the fixed path used in the file to your own fixed path by yourself!!!

[ Last edited by lotus516 on 2007-1-10 at 06:34 AM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
hover421 +1 2007-01-10 21:25
Attachments
2.rar (602 bytes, Credits to download 1 pts, Downloads: 34)
Floor 11 Posted 2007-01-10 21:31 ·  中国 湖南 长沙 联通
新手上路
Credits 18
Posts 7
Joined 2007-01-05 23:47
19-year member
UID 75546
Gender Male
Status Offline
Thanks lotus516, I just tried your bat at work and it works well. Really thank you!
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
+1 2010-07-11 18:32
Forum Jump: