You are welcome. No bother at all. Glad you figured out the mystery.
Batch Script Adding a Period (.) to File Name
Hi, I am testing a script to find the last file within a folder.
It can locate the correct file, but the resulting variable includes a period (.) within the file name.
Here's the script:
REM Copy the recent Friday evening's Diff Backup onto the drive G: My Passport device.
@echo on
set srcDir=F:\Backup\Differential Backup
set destdir=G:\My Passport\Differential Backup
cd /d F:\Backup\Differential Backup
FOR /f %f IN ('DIR /b /od *.zip') DO @SET last=%f
echo The most recently created file is %last%
:::
echo "%last"
:::
:eof
pause
This is the Windows Command results:
Microsoft Windows [Version 10.0.19045.3448]
(c) Microsoft Corporation. All rights reserved.
C:\Users\Todd>@echo on
C:\Users\Todd>set srcDir=F:\Backup\Differential Backup
C:\Users\Todd>set destdir=G:\My Passport\Differential Backup
C:\Users\Todd>cd /d F:\Backup\Differential Backup
F:\Backup\Differential Backup>FOR /f %f IN ('DIR /b /od *.zip') DO @SET last=%f
F:\Backup\Differential Backup>echo The most recently created file is %last%
The most recently created file is Diff-.56_S.zip
You will notice the actual file "Diff-56_S.zip" appears in the variable %last% with a period(.) immediately after "Diff-".
I have tried various script versions, but every one results with the period (.) withing the variable.
What causes that to happen?
Thanks!
Windows for home | Windows 11 | Files, folders, and storage
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
4 answers
Sort by: Most helpful
-
Anonymous
2023-09-24T10:45:11+00:00 My apologies ... I have discovered the problem.
The app that creates these files has actually embedded a period (.) into the file name.
Sorry to bother you and appreciate your help.
-
Deleted
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more
-
EmilyS726 241.6K Reputation points Independent Advisor2023-09-24T02:32:48+00:00 Hello, this is Emily.
I modified your codes to the following.. I recreated the scenario and it works for me:
@echo off
setlocal enabledelayedexpansion
set srcDir=F:\Backup\Differential Backup
set destdir=G:\My Passport\Differential Backup
cd /d %srcDir%
set last=
for /f "delims=" %%f in ('dir /b /od *.zip') do set "last=%%f"
echo The most recently created file is %last%
echo "%last%"
:end
pause