Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have somes files are updated everyday and named like "1706...", "1806..." (name same as the day file was created). So i wanna create a bat file to help me auto search for newest files then upload them to my ftp server. Any1 can help?

"search for newest files "
How many?
=====================================
If at first you don't succeed, you're about average.M2

This will copy the 9 newest to another directory, from where you can ftp them.
::=====================
@echo off
setLocal EnableDelayedExpansionfor /f "tokens=* delims= " %%a in ('dir/b/a-d/o-d') do (
set /a N+=1
if !N! gtr 9 goto :eof
copy %%a d:\outgoing
)
=====================================
If at first you don't succeed, you're about average.M2

ty Mechanix2Go
but when i mean "newest files", i mean all files were updated same day, i.e: 17068679.CSV,17068678.CSV,17068668.CSV... and i dont know exactly how many files. So i think ur script doesnt work this way right?

If they all have the same date & time, no it won't work.
If, for these 3 example files:
17068679.CSV,17068678.CSV,17068668.CSV
the 17068 bit is a date and the 679 etc are sequentil numbers, then try this:
::===================
@echo off
setLocal EnableDelayedExpansionfor /f "tokens=* delims= " %%a in ('dir/b/a-d/o-n *.csv') do (
set /a N+=1
if !N! gtr 9 goto :eof
copy %%a d:\outgoing
)
=====================================
If at first you don't succeed, you're about average.M2

ty Mechanic2Go
ur script works fine but like i said b4, I dont know exactly how many "newest files". In ur script it always copies 9 files, so if somedays it has more or less than 9, it will be problem.

@echo off
setLocal EnableDelayedExpansionset /p H=howmany ?
for /f "tokens=* delims= " %%a in ('dir/b/a-d/o-n *.csv') do (
set /a N+=1
if !N! gtr !H! goto :eof
copy %%a d:\outgoing
)
=====================================
If at first you don't succeed, you're about average.M2

ty Mechanix2Go
so I have to edit file batch everyday? No solution about auto check how many newest files then upload them?

Well you either use a fixed number of files or you change it on each run.
Can't think of a third option.
=====================================
If at first you don't succeed, you're about average.M2

so it turns out I need the script that can count how many the lastest files in the folder.
any idea?

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |