Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Copy newest file else keep folder empty

$
0
0
 would like a batch file in command line or written in VBSCRIPT for the following scenario:

There are 2 folders:

1-IncomingData 2-NewestData

The 1-IncomingData folder has several .txt files in it, new files arrive in this folder every day.

When I run the script, I would like to accomplish the following:

  1. Copy the newest/most recent text file from 1-IncomingData to 2-NewestData - only - if a new file is found in 1-IncomingData since the last time the script ran, otherwise do not copy it into 2-NewestData (in which case you would leave 2-NewestData folder empty)

The script below is incomplete and I cannot accomplish what I am looking for:

pushd "C:\Users\CP\Desktop\Data\1-IncomingData\" for /f "tokens=* delims= " %%G in ('dir/b/od') do (set newest=%%G) copy %newest% C:\Users\CP\Desktop\Data\2-NewestData\ popd

fc /b "%newest%" C:\Users\CP\Desktop\Data\2-NewestData>nul 2>&1 if %errorlevel% equ 0 (  del /q "%newest%" ) else (  copy /y "%newest%" C:\Users\CP\Desktop\Data\2-NewestData\ )

Any assistance would be greatly appreciated. Thanks in advance.



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>