×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Checking for files with current date using dos commands

Checking for files with current date using dos commands

Checking for files with current date using dos commands

(OP)
How can I use a dos scripting to check for files with current date

I get 4 files daily

File1_yyyymmdd
file2_yyyymmdd
file3_yyyymmdd
file4_yyyymmdd

RE: Checking for files with current date using dos commands

Send your directory search to a file then process that using a program written in the language of your choice.


Nic

RE: Checking for files with current date using dos commands

With DOS command you can get the current date from the variable DATE or from the command DATE /T.
Then you have to extract day, month and year from your date format, assemble the filename part _yyyymmdd and search for *_yyyymmdd

RE: Checking for files with current date using dos commands

you can try out this little example:

search_files.cmd

CODE

@echo off

rem given is date, e.g. NN dd.mm.yyyy
echo current date is: "%date%"

rem extract date from variable DATE
set mydate=%DATE:~3,10%
echo mydate=%mydate%

rem extract date from the command DATE /T
rem for /F "tokens=2" %%i in ('DATE /T') do set mydate=%%i
rem echo mydate=%mydate%

rem now extract day, month, year:
rem get day
set dd=%mydate:~0,2%
echo dd=%dd% 

rem get month
set mm=%mydate:~3,2%
echo mm=%mm% 

rem get year
set yyyy=%mydate:~6,4%
echo yyyy=%yyyy% 

rem create file name
set filename_part=_%yyyy%%mm%%dd%
echo filename_part=%filename_part%

rem search in subdirectories for files named: *_yyyymmdd
dir /s/b *%filename_part% 

Note: I have on my computer date in format Mo 04.03.2019

RE: Checking for files with current date using dos commands

You can cut out one step by using the /t parameter on the DATE command. This, on my system, returns dd/mm/ccyy.


Nic

RE: Checking for files with current date using dos commands

If I omit the /t switch on my Win7, then the command DATE shows me the current date and then it wants to enter other value to change it:

CODE

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

U:\>date
The current date is: ut 05.03.2019
Enter the new date: (dd-mm-yy) 

RE: Checking for files with current date using dos commands

gmoorthy, did any of this help?

RE: Checking for files with current date using dos commands

I would probably use basic as the step to extract the file names.

Ed Fair
Give the wrong symptoms, get the wrong solutions.

RE: Checking for files with current date using dos commands

>If I omit the /t switch on my Win7, then the command DATE shows me the current date and then it wants to enter other value to change it:

Yes, all the /t switch does it instruct the command not to prompt for a new date. It has no effect on the output format of the date, which is reliant on the regional settings.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close