0

My goal is to copy the latest file (based on modified date) in Windows to a different folder, and then rename the file to something different. My last line that is commented out was just a test to see that the copy command was working. Feel free to use whatever is installed by default in Windows.

Here's what I have so far:

cd C:\Users\Mac\Desktop\old
FOR /f %%i IN ('dir /o:-d /b') DO (set LAST=%%i goto stop)
:stop
copy /Y %LAST% C:\Users\Mac\Desktop\new\current.csv
# copy C:\Users\Mac\Desktop\old\a1.txt C:\Users\Mac\Desktop\new\current.csv

1 Answers1

0

This is the closest I got. Good enough for now. If anyone knows how to search for JUST *.csv files in the loop, let me know and I'll make your answer the correct answer. This seems to work though.

@echo off

setlocal

set "src=C:\Users\Mac\Desktop\old"
set "dst=C:\Users\Mac\Desktop\new"

pushd "%src%"
for /f "delims=" %%f in ('dir /b /a:-d /o:-d') do (
  del "%dst%\current.csv"
  copy "%%~f" "%dst%\current.csv"
  goto next
)

:next
popd