I have a program that have ongoing export of files. Another program needs to import these files.
But it only need to import the newest file within a "filename/date range".
The filename contains a 6 digit number (casenumber) and a date+timestamp
.
Example of file name:
732087_20190903114454043000
Picture for below color explanation.
Numbers in red are the casenumber.
Numbers in blue are the date (year/month/day).
Numbers in yellow are time (hour/minute/second/tenth or hundredth of a second.
Example of files created with ONLY same case number and Date stamp. (I isolated the range to only one Casenumber for this example)
732087_20190903114454043000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114452887000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114451713000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114446353000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114446161000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114445013000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114442719000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114439141000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114433660000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114431784000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114424999000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114423845000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114422669000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114421406000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114416004000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114414820000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114410392000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114405990000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114405784000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114404612000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114357807000.xml 18.979 03-09-2019 11:43 -a-- 732087_20190903114353325000.xml 18.979 03-09-2019 11:43 -a-- 732087_20190903114346777000.xml 18.979 03-09-2019 11:43 -a-- 732087_20190903114248766000.xml 18.979 03-09-2019 11:42 -a-- 732087_20190903114245183000.xml 18.979 03-09-2019 11:42 -a--
If I want to only move the last file (newest) created:
732087_20190903114454043000.xml
to a certain destination folder
ex: n:\Outbox\Projectdata\
and the rest in the same Casenumber range should be moved to an sub folder
in ex: n:\Outbox\Projectdata\old
A real example of several casenumbers created within same date and where the files I marked with bold should be moved to n:\Outbox\Projectdata\
the rest to n:\Outbox\Projectdata\old.
731218_20190903131544122000.xml 17.224 03-09-2019 13:15 -a-- 731218_20190903131108622000.xml 17.224 03-09-2019 13:11 -a-- 731218_20190903130833778000.xml 17.224 03-09-2019 13:08 -a-- 731218_20190903130819889000.xml 17.224 03-09-2019 13:08 -a-- 731218_20190903130332272000.xml 17.224 03-09-2019 13:03 -a-- 731218_20190903130329390000.xml 17.224 03-09-2019 13:03 -a-- 734107_20190903125649782000.xml 1.833 03-09-2019 12:56 -a-- 732087_20190903114454043000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114452887000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114451713000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114446353000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114446161000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114445013000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114442719000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114439141000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114433660000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114431784000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114424999000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114423845000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114422669000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114421406000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114416004000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114414820000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114410392000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114405990000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114405784000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114404612000.xml 18.979 03-09-2019 11:44 -a-- 732087_20190903114357807000.xml 18.979 03-09-2019 11:43 -a-- 732087_20190903114353325000.xml 18.979 03-09-2019 11:43 -a-- 732087_20190903114346777000.xml 18.979 03-09-2019 11:43 -a-- 732087_20190903114248766000.xml 18.979 03-09-2019 11:42 -a-- 732087_20190903114245183000.xml 18.979 03-09-2019 11:42 -a-- 731054_20190903110744981000.xml 18.851 03-09-2019 11:07 -a-- 731218_20190903102953782000.xml 17.224 03-09-2019 10:29 -a-- 731218_20190903102939235000.xml 17.224 03-09-2019 10:29 -a-- 731218_20190903102939093000.xml 17.224 03-09-2019 10:29 -a-- 731218_20190903102936730000.xml 17.224 03-09-2019 10:29 -a-- 731218_20190903102928927000.xml 17.224 03-09-2019 10:29 -a--
Is it above possible, to get an VBA / Powershell or other code to look at this folder, lets say once every hour and perform the mentioned moved of ONLY newest file within each Casenumber/date?
Problems that may occur:
If "move" script is running and in the meantime/same instant a new exportfile is created, would the script take that file(s) into account, and treat it in next run. So it does not accidentally move the file to OLD folder.
Possible solution: When script is running at first, maybe move the files to a temp folder, so if a new export file is created, the files in the temp foler is isolated from newly created files. Newly created files that would be trteated in the next script run.
I found a topic but not sure if it is useable in any way: How do I write a Windows batch script to copy the newest file from a directory?