Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Batch File change

66 views
Skip to first unread message

Mike NYC

unread,
Oct 16, 2021, 1:18:36 PM10/16/21
to
Hi ALL...

I have a simple search, copy, move batch file

I only does "todays" files...

Suppose I need yesterdays or 2 days ago or 3 etc etc

what would I change in here:

del c:\todayhtr\*.* /q

set filestocopy=c:\htr\%DATE:~4,2%%DATE:~7,2%*.*

copy %filestocopy% c:\todayhtr

thxs guys

Zaidy036

unread,
Oct 16, 2021, 2:37:11 PM10/16/21
to
Menu choice to proceed but I suggest using Julian dates so changing
months or years also covered.

For to/from Julian look at
<https://www.robvanderwoude.com/datetimentmath.php>

Look at batch command Choice for something like following:

ECHO "%_SPC6%Select which day to copy"
ECHO %_SPC6%----------------------------------------------
ECHO %_SPC12%0 Today
ECHO %_SPC12%1 Yesterday
ECHO %_SPC12%2 Two days ago
ECHO %_SPC12%3 Three days ago
ECHO %_SPC12%9 Exit without copying"
CHOICE /C 01239 /N /M "%_SPC6%Choose an option from above list"

IF %ERRORLEVEL% EQU 9 EXIT
IF %ERRORLEVEL% EQU 3 GOTO _DoIt3
IF %ERRORLEVEL% EQU 2 GOTO _DoIt2
IF %ERRORLEVEL% EQU 1 GOTO _DoIt1


Zaidy036

unread,
Oct 16, 2021, 2:40:36 PM10/16/21
to
On 10/16/2021 1:18 PM, Mike NYC wrote:

Mike NYC

unread,
Oct 16, 2021, 2:52:24 PM10/16/21
to
I'm at a loss here.....
Can you change my original code and include yesterdays date

this is what the files look like that I did with above script...
1016B02.ARP
1016B03.ARP
1016B04.ARP
etc
etc

the first 4 digits are the date , everything after that will be different
I just want all files move with the specific date that I chose

Zaidy036

unread,
Oct 16, 2021, 3:46:05 PM10/16/21
to
Do you want a batch to do the work for you?

Then to design a batch you have to decide ALL of the variations you want
to include: How many different days, source directories, and destination
directories. Will a change of year or month cause a problem?

Depending on desires one can then use menu choices like I showed or
batch command input variables like %1 %2 %3.

FORFILES might also be a good command to use.


If the only variable is date then start your batch with _MoveBat %1
where %1 is the MMDD you want.

_MoveBat
---------------
DEL c:\todayhtr\*.* /q
COPY c:\htr\%1*.* C:\todayhtr\

PS: I think you have a typo here
set filestocopy=c:htr\\%DATE:~4,2%%DATE:~7,2%*.*
^^ ^^







Mike NYC

unread,
Oct 16, 2021, 4:39:48 PM10/16/21
to
Thxs Z.....

I used your DEL & COPY Lines and "everything" was copied over ........it DID NOT pluck out any specific dates

Sorry to make this a big thing...

this is not complicated ...

using 2 folders "HTR" and "todayhtr"

HTR has various files with different dates in it...like my sample above

all I need is to select the date I want and copy it over...

My initial bat file WORKED....but I cant get any other day but today....I want it to be of my choice...

We are almost there....but not just yet :)

Mike

Herbert Kleebauer

unread,
Oct 16, 2021, 6:41:04 PM10/16/21
to
The simplest way would be to specify the date and not the
offset to the current date:

del c:\todayhtr\*.* /q
set filestocopy=c:\htr\%1*.*
if [%1]==[] set filestocopy=c:\htr\%DATE:~4,2%%DATE:~7,2%*.*
copy %filestocopy% c:\todayhtr

If you start the batch without a parameter the current date is used
otherwise the given date is used.

But if you really want to calculate yesterdays date within the batch,
read the thread "Get date of recent weekday" from a few weeks ago.






Zaidy036

unread,
Oct 16, 2021, 8:06:32 PM10/16/21
to
Did you really mean c:htr\\ or should that be c:\htr\?

If file names have a space then enclose in " ". Safest is to use " " all
of the time: COPY "c:\htr\%1*.*" C:\todayhtr\

Make sure %1 does NOT have a space at the end.

Look at c:\htr\ and make sure files exist with date you are testing. You
could add an following to batch before copy to warn if no files with date:
IF NOT EXIST "c:\htr\%1*.*" NUL || (ECHO *** No Files with that date ***
& Exit)

Zaidy036

unread,
Oct 16, 2021, 9:42:14 PM10/16/21
to
Sorry but command should be
(ECHO *** No Files with that date *** & PAUSE & Exit)

Robert Roland

unread,
Oct 17, 2021, 8:14:04 AM10/17/21
to
On Sat, 16 Oct 2021 10:18:35 -0700 (PDT), Mike NYC
<msalo...@gmail.com> wrote:

>Suppose I need yesterdays or 2 days ago or 3 etc etc

Date arithmetics in batch is a bit too hardcore for me, so I tend to
"cheat" and use powershell or vbscript for that. Here's how to get
yesterday's date in the format you prefer, in one line:

for /f %%n in ('powershell -Command "(Get-Date).AddDays(-1)|Get-Date
-Format 'yyyyMMdd'"') do set mydate=%%n

Just change the format string to match your particular locale. Change
the "-1" the number of days you wan to calculate backwards.
--
RoRo
0 new messages