Batch limits?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Panavision
Posts: 3
Joined: 04 Dec 2013 07:28

Batch limits?

#1 Post by Panavision » 04 Dec 2013 07:51

Are there limitations to the complexity of a batch file? I'm trying to write an automation script that will function as an all-in-one configuration/daily run-file.

Example:

I have a spreadsheet tool that is dependent on external daily report files. They get stored to a server that has no effective directory management; so, the files for the entire year are just dumped into one folder. Thankfully, the server has decent naming strings so you can figure out what the report is by reading the file name. So, a report that was created on May 5th, 2013 at center 2501 gets named this way: Summary_0A10751_2501_2013-05-05.

I already have the script to create the annual directory folder containing all the months and the days for each month:

Code: Select all

@echo off & setlocal
set year=%1
if "%year%"=="" set /p year=Year?
if "%year%"=="" goto :eof
set /a mod=year %% 400
if %mod%==0 set leap=1 && goto :mkyear
set /a mod=year %% 100
if %mod%==0 set leap=0 && goto :mkyear
set /a mod=year %% 4
if %mod%==0 set leap=1 && goto :mkyear
set leap=0

:mkyear
call :mkmonth 01 Jan 31
call :mkmonth 02 Feb 28+leap
call :mkmonth 03 Mar 31
call :mkmonth 04 Apr 30
call :mkmonth 05 May 31
call :mkmonth 06 Jun 30
call :mkmonth 07 Jul 31
call :mkmonth 08 Aug 31
call :mkmonth 09 Sep 30
call :mkmonth 10 Oct 31
call :mkmonth 11 Nov 30
call :mkmonth 12 Dec 31
goto :eof

:mkmonth
set month=%1
set mname=%2
set /a ndays=%3
for /l %%d in (1,1,9)        do mkdir %year%\%month%-%mname%\%month%-0%%d
for /l %%d in (10,1,%ndays%) do mkdir %year%\%month%-%mname%\%month%-%%d


And the script to pull new reports daily from the server and place them in a folder on the local drive:

Code: Select all

ECHO [message]
XCOPY "X:\Center Reports\Financials\Center Summary Reports" "C:\Users\Dude\Desktop\Financial Tracker\Center Summary Reports" /D /E /C /R /I /K /Y


But is there a way to otherwise combine these and add a subroutine that will look at the file names on the server and match the date and then xcopy it in the proper date folder? Or do I need a third script altogether?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch limits?

#2 Post by foxidrive » 04 Dec 2013 09:06

Is the filename format a known and constant layout? Is the date always the last 10 characters of the filename?

Panavision
Posts: 3
Joined: 04 Dec 2013 07:28

Re: Batch limits?

#3 Post by Panavision » 05 Dec 2013 01:47

Constant layout yes but character length will fluctuate based on the report identifier, i.e., "0A10751". This unique identifier will change for every report as it is generated by the server; but the rest of the layout will always follow that pattern: Title_UniqueID_CenterNumber_Year-Month-Day.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch limits?

#4 Post by foxidrive » 05 Dec 2013 04:54

I think now that you want to sort into categories, not just sorting by year, month or day - which would be easy if the last 10 characters is always the date in YYYY-MM-DD format

Panavision
Posts: 3
Joined: 04 Dec 2013 07:28

Re: Batch limits?

#5 Post by Panavision » 05 Dec 2013 13:37

If it helps, the reports are pdf's, and the date is always at the end of the string, always in that format. There isn't a way to modify the code to start at the end of a string and read backwards?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch limits?

#6 Post by foxidrive » 05 Dec 2013 19:37

This will create folders in the current folder called something like 2012\04\31 and move the *2004-04-31.pdf files into that folder, and so on.
It might not be quite what you need, but explain further if you need some extra help,

Code: Select all

@echo off
setlocal enabledelayedexpansion
for %%a in (*.pdf) do (
   set "name=%%~na"
   set year=!name:~-10,4!
   set month=!name:~-5,2!
   set day=!name:~-2,2!
 md "!year!\!month!\!day!" 2>nul
 move "%%a" "!year!\!month!\!day!" >nul
)

Post Reply