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-09 03:50
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] How to back up files and folders by time period!! View 955 Replies 7
Original Poster Posted 2008-07-14 12:07 ·  中国 广东 深圳 电信
初级用户
Credits 27
Posts 10
Joined 2006-12-14 10:23
19-year member
UID 73502
Gender Male
Status Offline
Folders aa , bb

Copy the files generated under folder aa from 2 to 5 o'clock today to the folder generated under bb from 2 to 5 o'clock today.

Then copy the files and folders generated under folder bb from 2 to 5 o'clock today to the server...

I'm not capable enough to write it out, so I'm asking everyone here!!
Floor 2 Posted 2008-07-14 12:13 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
What day is "today"?
Hehe, couldn't you give a few more conditions? Don't make the person helping you have to assume the conditions themselves.
批处理之家新域名:www.bathome.net
Floor 3 Posted 2008-07-14 14:55 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
For reference only

@echo off
setlocal enabledelayedexpansion
rem Set the date and time format
reg add "HKEY_CURRENT_USER\Control Panel\International" /v sTimeFormat /t REG_SZ /d HH:mm:ss /f>nul
reg add "HKEY_CURRENT_USER\Control Panel\International" /v sShortDate /t REG_SZ /d yyyyMMdd /f>nul
rem Set the source folder
set SrcDir=C:\test\a
rem Set the target folder
set DstDir=C:\test\b
rem Suppose we want to delete text files created between 9 AM and 5 PM
set begint=%date%09
set endt=%date%17
for %%a in ("%SrcDir%\*.txt") do call :getdt "%%a"
goto :eof
:getdt
for /f "skip=5 tokens=1,2" %%a in ('dir /tc %1') do (
if "%%a%%b" geq "%begint%" (
if "%%a%%b" leq "%endt%" (
del /q %1
)
)
goto :eof
)
Floor 4 Posted 2008-07-14 16:11 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Whoa, hat, aren't you making it too complicated? You even brought the registry into it.
批处理之家新域名:www.bathome.net
Floor 5 Posted 2008-07-14 16:19 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
I was considering that the date/time format might be different from the OP's, and I was too lazy to ask, so I just did it the hard way, hehe.
Floor 6 Posted 2008-07-14 21:51 ·  中国 广东 深圳 福田区 电信
初级用户
Credits 27
Posts 10
Joined 2006-12-14 10:23
19-year member
UID 73502
Gender Male
Status Offline
Sorry, I didn't explain it clearly..

Because data has to be collected every day... so "today" means the current system date..

For example, if today is July 14 (Ghost Festival, sheesh)
find all files and folders generated in folder aa on July 14 from 2 to 5 o'clock.
If found, copy them into a folder under bb
Otherwise, just end...
-----------------------------------------------------------
As for "a folder under bb," if there are files under aa generated from 2 to 5 o'clock, then "a folder under bb" will be generated. This folder is automatically generated by the system and named with a string of numbers, so the folder name is unknown..... It can only be judged by creation time...

Not sure if this makes it clearer....

[ Last edited by xiaohangdos on 2008-7-14 at 09:52 PM ]
Floor 7 Posted 2008-07-16 09:35 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
The conditions given by the OP still aren't enough. There's no way around it, I can only make assumptions myself:
aa and bb are both folders under d:\test, and the system time format is 2008-07-16 Wednesday 8:40:21.46

@echo off
set "code=abcdefghijklmnopqrstuvwxyz"&set n=26
:again
set /a a=%random%%%%n%
call,set a=%%code:~%a%,1%%
call,set code=%%code:%a%=%%
set str=%str%%a%&set /a n-=1
if %n% gtr 26 goto again
set t=%date:~,-4%
for /f "delims=" %%i in ('dir /s /b d:\test\aa') do if "%%~ti" gtr "%t%02:00" if "%%~ti" lss "%t%05:00" xcopy /y "%%i" d:\test\bb\%str%\


[ Last edited by zw19750516 on 2008-7-16 at 09:49 AM ]
批处理之家新域名:www.bathome.net
Floor 8 Posted 2008-07-16 13:01 ·  中国 广东 深圳 电信
初级用户
Credits 27
Posts 10
Joined 2006-12-14 10:23
19-year member
UID 73502
Gender Male
Status Offline
Seems like it doesn't work..

But thanks to the poster above....
I'll just learn slowly and write it myself later..
Forum Jump: