Question: I want to copy the latest file from a Folder(and subfolders) to a new location.
The following code works well, BUT I do not want to filter by Date AND Time (/O:D), but DATE only, so that all files from the same date will be copied to the new location as the latest files.

```
FOR /F "delims=|" %%I IN ('DIR "D:\Backups\DB\*.bak" /B /O:D /S') DO SET NewestFile=%%I
copy "%NewestFile%" "D:\Latest"

```

Answer: 
You can use xcopy `/D` to accomplish what you want :

```
 /D:mm-dd-yyyy
                Copy files changed on or after the specified date.
                If no date is given, copy only files whose
                source date/time is newer than the destination time.

```
```
@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set "dt=%%a"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"

set datestamp=%MM%-%DD%-%YYYY%

XCOPY D:\Backups\DB\*.bak D:\Latest\ /S /D:%datestamp%

```

PROBLEM:

This code does what I want, BUT it copies the parent sub-folder of the file as well. Since each .bak file in the D:\Backups\DB\ folder, resides in a subdirectory of D:\Backups\DB. eg:

D:\Backups\DB\2013-12-01\20131201.bak are being copied as 

```
D:\Latest\2013-12-01\20131201.bak

```

and not

```
D:\Latest\20131201.bak

```

How do I prevent the parent sub-folder of the .bak file from being copied to the new location?