Discussion:
Batch File change
(too old to reply)
Mike NYC
2021-10-16 17:18:35 UTC
Permalink
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
2021-10-16 18:37:09 UTC
Permalink
Post by Mike NYC
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
del c:\todayhtr\*.* /q
set filestocopy=c:\htr\%DATE:~4,2%%DATE:~7,2%*.*
copy %filestocopy% c:\todayhtr
thxs guys
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
Mike NYC
2021-10-16 18:52:23 UTC
Permalink
Post by Zaidy036
Post by Mike NYC
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
del c:\todayhtr\*.* /q
set filestocopy=c:\htr\%DATE:~4,2%%DATE:~7,2%*.*
copy %filestocopy% c:\todayhtr
thxs guys
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>
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
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
2021-10-16 19:46:03 UTC
Permalink
Post by Mike NYC
Post by Zaidy036
Post by Mike NYC
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
del c:\todayhtr\*.* /q
set filestocopy=c:htr\\%DATE:~4,2%%DATE:~7,2%*.*
copy %filestocopy% c:\todayhtr
thxs guys
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>
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
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
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
2021-10-16 20:39:47 UTC
Permalink
Post by Zaidy036
Post by Mike NYC
Post by Zaidy036
Post by Mike NYC
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
del c:\todayhtr\*.* /q
set filestocopy=c:htr\\%DATE:~4,2%%DATE:~7,2%*.*
copy %filestocopy% c:\todayhtr
thxs guys
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>
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
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
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%*.*
^^ ^^
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
Zaidy036
2021-10-17 00:06:30 UTC
Permalink
Post by Mike NYC
Post by Zaidy036
Post by Mike NYC
Post by Zaidy036
Post by Mike NYC
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
del c:\todayhtr\*.* /q
set filestocopy=c:htr\\%DATE:~4,2%%DATE:~7,2%*.*
copy %filestocopy% c:\todayhtr
thxs guys
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>
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
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
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%*.*
^^ ^^
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
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
2021-10-17 01:42:13 UTC
Permalink
Post by Zaidy036
Post by Mike NYC
Post by Zaidy036
Post by Mike NYC
Post by Zaidy036
Post by Mike NYC
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
del c:\todayhtr\*.* /q
set filestocopy=c:htr\\%DATE:~4,2%%DATE:~7,2%*.*
copy %filestocopy% c:\todayhtr
thxs guys
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>
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
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
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%*.*
^^ ^^
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
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
IF NOT EXIST "c:\htr\%1*.*" NUL || (ECHO *** No Files with that date ***
& Exit)
Sorry but command should be
(ECHO *** No Files with that date *** & PAUSE & Exit)
Zaidy036
2021-10-16 18:40:35 UTC
Permalink
Post by Mike NYC
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
del c:\todayhtr\*.* /q
set filestocopy=c:\htr\%DATE:~4,2%%DATE:~7,2%*.*
copy %filestocopy% c:\todayhtr
thxs guys
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
Herbert Kleebauer
2021-10-16 22:41:01 UTC
Permalink
Post by Mike NYC
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
del c:\todayhtr\*.* /q
set filestocopy=c:\htr\%DATE:~4,2%%DATE:~7,2%*.*
copy %filestocopy% c:\todayhtr
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.
Robert Roland
2021-10-17 12:14:01 UTC
Permalink
On Sat, 16 Oct 2021 10:18:35 -0700 (PDT), Mike NYC
Post by Mike NYC
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
Loading...