Copy Newest File in a Directory and Rename

March 3, 2012 at 11:46:19
Specs: 2008 Server Standard r2 x64
I found the batch below elsewhere on this excellent site which is exactly what I want to do but when I execute it just copies all the files from the source directory and does not rename them , I've played around with this for several hours now and am not making any progress. This is on a Windows 2008 R2 server, not sure if that makes a diffrence or not?

@echo off
setLocal EnableDelayedExpansion
pushd G:\BO\Donnette\CCIEdits\Downloads

for /f "tokens=* delims= " %%a in ('dir/b/od') do (
set newest=%%a
copy !newest! x:\mystuff\newest

See More: Copy Newest File in a Directory and Rename

Report •

March 4, 2012 at 00:53:57
Use this, echo f | xcopy !newest! x:\mystuff\newest /Q /Y.
Here's an example, if i want to copy x.bat from desktop to %tmp% as 2x.bat there is no need for the rename command.
echo f | xcopy C:\Users\user\Desktop\x.bat x:\mystuff\newest\2x.bat /Q /Y.

Report •
Related Solutions

Ask Question