Crazy Dave
New member
- Local time
- 10:38 PM
- Posts
- 6
- OS
- Windows 11
Good morning,
I hope someone can help me with this. I have the following batch file that I'm comparing the most current dates for 3 files. I want to open the location for the most current file folder. I'm not sure what the correct syntax is to open a folder path location that's held within a variable.
@echo off
setlocal
:: Set file paths
set "file1=C:\Folder1\File1.accdb"
set "file2=C:\Folder2\File2.accdb"
set "file3=C:\Folder3\File3.accdb"
:: Get timestamps
for %%F in ("%file1%") do set "date1=%%~tF"
for %%F in ("%file2%") do set "date2=%%~tF"
for %%F in ("%file3%") do set "date3=%%~tF"
:: Display timestamps
echo File 1: %file1% - %date1%
echo File 2: %file2% - %date2%
echo File 3: %file3% - %date3%
:: Compare dates
set "newest= Folder1"
set "newestDate=%date1%"
if "%date2%" GTR "%newestDate%" (
set "newest= Folder2"
set "newestDate=%date2%"
)
if "%date3%" GTR "%newestDate%" (
set "newest= Folder3"
set "newestDate=%date3%"
)
echo.
echo The most recently modified file is: %newest% (%newestDate%)
endlocal
%SystemRoot%\explorer.exe %newest%
pause
I hope someone can help me with this. I have the following batch file that I'm comparing the most current dates for 3 files. I want to open the location for the most current file folder. I'm not sure what the correct syntax is to open a folder path location that's held within a variable.
@echo off
setlocal
:: Set file paths
set "file1=C:\Folder1\File1.accdb"
set "file2=C:\Folder2\File2.accdb"
set "file3=C:\Folder3\File3.accdb"
:: Get timestamps
for %%F in ("%file1%") do set "date1=%%~tF"
for %%F in ("%file2%") do set "date2=%%~tF"
for %%F in ("%file3%") do set "date3=%%~tF"
:: Display timestamps
echo File 1: %file1% - %date1%
echo File 2: %file2% - %date2%
echo File 3: %file3% - %date3%
:: Compare dates
set "newest= Folder1"
set "newestDate=%date1%"
if "%date2%" GTR "%newestDate%" (
set "newest= Folder2"
set "newestDate=%date2%"
)
if "%date3%" GTR "%newestDate%" (
set "newest= Folder3"
set "newestDate=%date3%"
)
echo.
echo The most recently modified file is: %newest% (%newestDate%)
endlocal
%SystemRoot%\explorer.exe %newest%
pause
My Computer
System One
-
- OS
- Windows 11
- Computer type
- PC/Desktop
- Manufacturer/Model
- Dell