Bat file for moving files

2019-08-19 02:21发布

I want to create one bat file that will move files from one location to one backup folder. Condition is I need to move all folders which are older than 30 days inside parent directory. Name of folder is creation date of folder.

For example: All files of 17 October 2012 would be there inside folder named 10172012.Source folders are:

C:\Data\DataIn\Processed\10172012

C:\Data\DataIn\Processed\09172012

C:\Data\DataIn\Processed\08172012

So on today bat file should move folders "09172012", "08172012" to destination backup folder:

D:\Backup\Processed\

2条回答
来,给爷笑一个
2楼-- · 2019-08-19 02:41

Using shell scripting it was easier to do. Finally I implemented this using shell scripting.

查看更多
一夜七次
3楼-- · 2019-08-19 02:49
@echo off
setlocal EnableDelayedExpansion
rem Get Julian Day number of today's date
for /F "tokens=1-3 delims=/" %%a in ("%date%") do (
   set /A m=1%%a %% 100, d=1%%b %% 100, y=%%c
)
set /A A=(m-14)/12, todayJDN = (1461*(y+4800+A))/4 + (367*(m-2-12*A))/12 - (3*((y+4900+A)/100))/4 + d - 32075
rem Process all folders
for /D %%a in (*) do (
   rem Get Julian Day Number of this folder
   set folder=%%a
   set /A m=1!folder:~0,2! %% 100, d=1!folder:~2,2! %% 100, y=!folder:~4!
   set /A "A=(m-14)/12, folderJDN = (1461*(y+4800+A))/4 + (367*(m-2-12*A))/12 - (3*((y+4900+A)/100))/4 + d - 32075"
   rem Move folder if it is older than 30 days
   set /A daysOlder=todayJDN - folderJDN
   if !daysOlder! gtr 30 move %%a D:\Backup\Processed\
)

Julian Day Numbers are described here: http://www.hermetic.ch/cal_stud/jdn.htm

查看更多
登录 后发表回答