file path with changing folder name

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
user124
Posts: 4
Joined: 20 Feb 2020 09:51

file path with changing folder name

#1 Post by user124 » 28 Apr 2020 11:42

Hello everyone,

I am trying to create a batch file that will essentially look into a specific folder to check for missing files. However, the folder changes everyday and a new folder is created everyday with previous business day (t-1) as the folder name. Hence, I am trying to create a dynamic batch script which will select the folder with the latest date as its folder name. Here is an example of what the path to the folder would look like:
C:\Users\UserA\Ad_Hoc\27Feb2020\Folder_A\File_A

The folder name in bold is what would change everyday and everything else stays consistent. Is there a way to make the path dynamic in terms of the changing folder name?

Thanks!

jfl
Posts: 130
Joined: 26 Oct 2012 06:40
Location: Saint Hilaire du Touvet, France
Contact:

Re: file path with changing folder name

#2 Post by jfl » 29 Apr 2020 09:51

Hello,

Try using subroutines :jdate and :jdate2date from this very site library of functions:
https://www.dostips.com/DtCodeCmdLib.php#Function.jdate

Ex:

Code: Select all

call :jdate TODAY				&:# Get today's day number
set /a "YESTERDAY=TODAY-1"			&:# Get yesterday's day number
call :jdate2date YESTERDAY YEAR MONTH DAY	&:# Get yesterday's year/month/day 
I'll leave it to you to convert the numeric month to a string :-)
Also, there's the special case of January 1st that needs to be handled!

Eureka!
Posts: 89
Joined: 25 Jul 2019 18:25

Re: file path with changing folder name

#3 Post by Eureka! » 29 Apr 2020 18:54

user124 wrote:
28 Apr 2020 11:42
a new folder is created everyday with previous business day (t-1) as the folder name. [...]
Here is an example of what the path to the folder would look like:
C:\Users\UserA\Ad_Hoc\27Feb2020\Folder_A\File_A
If you could convince the person or system that creates these folders to use a date format like 2020-02-27 (year-month-day), that would make your life *a lot* easier as this would make these dates sortable.

Post Reply