I am a batch file noob and while I can get most to work, I am struggling badly with this one.
I am trying to copy the most recent Firefox Bookmark Backup file of all my users and this is what I got so far:
@echo OFF
for /f %%a in (' dir /b /ad "%APPDATA%\Mozilla\Firefox\Profiles\*default-esr*" ') do (
set "wildcard=%APPDATA%\Mozilla\Firefox\Profiles\%%a\bookmarkbackups"
for /f %%b in (' dir "%wildcard%\*.jsonlz4" /b /o-d /tw 2^>nul ') do (
set "newestfile=%%b" & goto foundfile
)
)
:foundfile
echo %wildcard%\%newestfile%
xcopy "%wildcard%\%newestfile%" "\\<server IP>\copy\%USERNAME%\firefox\bookmarkbackups\" /h /i /k /s /y
The first variable "wildcard" returns the expected path, but I cannot seem to get the second variable "newestfile" to return anything.
I've been trying to adapt this topic to fit my needs: Get newest file in directory with specific extension
Also, I've read on here that I need to resolve each wildcard separately, which I think I am doing...
I've tried "for /d" but that puts a ' in place of the expected wildcard values.
I am completely lost here, can someone help?