List the files with in two datetime
Moderator: DosItHelp
Re: List the files with in two datetime
Thanks Antonio & Dave.
cmd /V:ON /C "for /F "skip=5 tokens=1-7* delims=/: " %a in ('dir /A-D /T:C f:\ani\*.*') do @set h=%d&(if %f equ p.m. set /A "h=(1%d+12-100)">NUL)&set f=%c%b%a!h!%e&if "!f!" geq "20140304034534" if "!f!" leq "20150321231232" echo %a/%b/%c %d:%e %f %g %h"
This command is good, but it is not considering the Time. Please let me know how to use AM/PM timings. Is it 24hr or 12Hr.
Is there any way to check the files in subfolders also. I am using *.* but it is not checking the files in subfolders.
@Dave, Sorry for confusion. Initially we were asked to write batch file , later came to know that we will not be having the permissions to save the files in the client location. So we were trying for single line command
Thanks
cmd /V:ON /C "for /F "skip=5 tokens=1-7* delims=/: " %a in ('dir /A-D /T:C f:\ani\*.*') do @set h=%d&(if %f equ p.m. set /A "h=(1%d+12-100)">NUL)&set f=%c%b%a!h!%e&if "!f!" geq "20140304034534" if "!f!" leq "20150321231232" echo %a/%b/%c %d:%e %f %g %h"
This command is good, but it is not considering the Time. Please let me know how to use AM/PM timings. Is it 24hr or 12Hr.
Is there any way to check the files in subfolders also. I am using *.* but it is not checking the files in subfolders.
@Dave, Sorry for confusion. Initially we were asked to write batch file , later came to know that we will not be having the permissions to save the files in the client location. So we were trying for single line command
Thanks
Re: List the files with in two datetime
Will be much easier with powershell if one-liner is required....
Re: List the files with in two datetime
ani wrote:Thanks Antonio & Dave.
cmd /V:ON /C "for /F "skip=5 tokens=1-7* delims=/: " %a in ('dir /A-D /T:C f:\ani\*.*') do @set h=%d&(if %f equ p.m. set /A "h=(1%d+12-100)">NUL)&set f=%c%b%a!h!%e&if "!f!" geq "20140304034534" if "!f!" leq "20150321231232" echo %a/%b/%c %d:%e %f %g %h"
This command is good, but it is not considering the Time. Please let me know how to use AM/PM timings. Is it 24hr or 12Hr.
Is there any way to check the files in subfolders also. I am using *.* but it is not checking the files in subfolders.
@Dave, Sorry for confusion. Initially we were asked to write batch file , later came to know that we will not be having the permissions to save the files in the client location. So we were trying for single line command
Thanks
Certainly looks like the code is taking into consideration the time. Can see that plain as day.
Code: Select all
@set h=%d&(if %f equ p.m. set /A "h=(1%d+12-100)"
As far as saving files, you will have to at some point have this code saved to a file. You can't tell me you are going to memorize this!
Re: List the files with in two datetime
ani wrote:Thanks Antonio & Dave.
cmd /V:ON /C "for /F "skip=5 tokens=1-7* delims=/: " %a in ('dir /A-D /T:C f:\ani\*.*') do @set h=%d&(if %f equ p.m. set /A "h=(1%d+12-100)">NUL)&set f=%c%b%a!h!%e&if "!f!" geq "20140304034534" if "!f!" leq "20150321231232" echo %a/%b/%c %d:%e %f %g %h"
This command is good, but it is not considering the Time. Please let me know how to use AM/PM timings. Is it 24hr or 12Hr.
Is there any way to check the files in subfolders also. I am using *.* but it is not checking the files in subfolders.
A couple points here:
- As said before, "this method is locale dependant, although a simple change in "%%c%%a%%b" order for the appropriate one (like "%%c%%b%%a") would be enough to fix this point... Perhaps a small adjustment may be required in the "tokens=1-7*" part". The method assume that the output of DIR command have the following format (as shown in the output example):
Code: Select all
18/05/2013 02:04 p.m. 1,336 Permutations.bat
DD/MM/YYYY HH:MM ?.m. size filename
If the output of DIR command is different in your computer ("locale dependant"), the line requires a small adjustment; for example, if the date order is MM/DD/YYYY or the AM/PM indicator have a space, like in "p. m.". - As said before, "this method don't include the seconds... both startDate and endDate must be given in YYYYMMDDHHMM format" as shown in the example: C:\> between 201301010000 201331120000. Try:
Code: Select all
if "!f!" geq "201403040345" if "!f!" leq "201503212312"
- If you want to check files in subfolders, use /S switch in DIR command, like in: 'dir /A-D /T:C /S f:\ani'.
If after check previous points you still don't get the desired output, insert an ECHO command before the second IF, like in: &ECHO if "!f!" geq "201403040345" ..., so we may review what exactly are the processed values.
Antonio
Re: List the files with in two datetime
Thanks Antonio.
My Cmd and output is a below
cmd /V:ON /C "for /F "skip=5 tokens=1-7* delims=/: " %a in ('dir /s /A-D /T:C f:\ani\*.*') do @set "hour=%d"&(if "%f" equ "p.m." set /A
"hour=(1%d+12)%100")&set fileDate=%c%a%bhour%e&echo if "!fileDate!" geq "20140305122323" if "!fileDate!" leq "20150421150909" echo %a/%b/%c %d:%e %f %g %h"
The output is
if "20150421hour26" geq "20140305122323" if "20150421hour26" leq "20150421150909" echo 04/21/2015 12:26 PM 14,865 Address.docx
if "20150420hour17" geq "20140305122323" if "20150420hour17" leq "20150421150909" echo 04/20/2015 03:17 PM 56,534 Feb-2015.png
Why I am getting filedate as "20150421hour26", actually the file date is 20150421 12:26 PM.
May be for this reason the condition is not checking datetime.
Thanks
My Cmd and output is a below
cmd /V:ON /C "for /F "skip=5 tokens=1-7* delims=/: " %a in ('dir /s /A-D /T:C f:\ani\*.*') do @set "hour=%d"&(if "%f" equ "p.m." set /A
"hour=(1%d+12)%100")&set fileDate=%c%a%bhour%e&echo if "!fileDate!" geq "20140305122323" if "!fileDate!" leq "20150421150909" echo %a/%b/%c %d:%e %f %g %h"
The output is
if "20150421hour26" geq "20140305122323" if "20150421hour26" leq "20150421150909" echo 04/21/2015 12:26 PM 14,865 Address.docx
if "20150420hour17" geq "20140305122323" if "20150420hour17" leq "20150421150909" echo 04/20/2015 03:17 PM 56,534 Feb-2015.png
Why I am getting filedate as "20150421hour26", actually the file date is 20150421 12:26 PM.
May be for this reason the condition is not checking datetime.
Thanks
Re: List the files with in two datetime
ani wrote:Why I am getting filedate as "20150421hour26", actually the file date is 20150421 12:26 PM.
Because of this code.
Code: Select all
set fileDate=%c%a%bhour%e
Re: List the files with in two datetime
Hi,
cmd /V:ON /C "for /F "tokens=1-7* delims=/: " %a in ('dir /s /A-D /T:C f:\ani\') do @set fileDate=%c%a%b%d%e&if "!fileDate!" geq "201403050101" if "!fileDate!" leq "201504211209" echo %a/%b/%c %d:%e %f %g %h"
The output of the above command is
04/20/2015 03:17 PM 45,23 abc.docx
04/21/2015 02:08 PM 34 xyz.png
But the end date is 201504211209, it should not display xyz.png because its time is 02:08 PM which is greater than 1209
Could any one help me out how to handle the Time.
Thanks
cmd /V:ON /C "for /F "tokens=1-7* delims=/: " %a in ('dir /s /A-D /T:C f:\ani\') do @set fileDate=%c%a%b%d%e&if "!fileDate!" geq "201403050101" if "!fileDate!" leq "201504211209" echo %a/%b/%c %d:%e %f %g %h"
The output of the above command is
04/20/2015 03:17 PM 45,23 abc.docx
04/21/2015 02:08 PM 34 xyz.png
But the end date is 201504211209, it should not display xyz.png because its time is 02:08 PM which is greater than 1209
Could any one help me out how to handle the Time.
Thanks
Re: List the files with in two datetime
I don't understand why you modify the posted code and then you ask why it don't works, or why you don't follow the indications given. It is difficult to help you when you can't follow very simple indications. Anyway, I think this is the right code for you:
The core problem was that the AM/PM indication in your computer use upper case letters with no points, like in PM, but my original code use lower case letters with points, like in p.m..
If you still have problems with this code, you must post the code enclosed between code tags, that is, enter the word "code" (without quotes) enclosed in square braquets in a line, followed by the code and after it insert a line with "/code" (without quotes) enclosed in square braquets. Do the same thing for the output sample.
I am sorry, but I will not answer future replies from you if you don't include the code used, that must be the same code posted above, or if you don't include an explanation of the changes you did vs. the posted code.
Antonio
Code: Select all
cmd /V:ON /C "for /F "skip=5 tokens=1-7* delims=/: " %a in ('dir /S /A-D /T:C f:\ani') do @set hour=%d&(if %f equ PM set /A "hour=(1%d+12-100)">NUL)&set fileDate=%c%a%b!hour!%e&if "!fileDate!" geq "201403050101" if "!fileDate!" leq "201504211209" echo %a/%b/%c %d:%e %f %g %h"
The core problem was that the AM/PM indication in your computer use upper case letters with no points, like in PM, but my original code use lower case letters with points, like in p.m..
If you still have problems with this code, you must post the code enclosed between code tags, that is, enter the word "code" (without quotes) enclosed in square braquets in a line, followed by the code and after it insert a line with "/code" (without quotes) enclosed in square braquets. Do the same thing for the output sample.
I am sorry, but I will not answer future replies from you if you don't include the code used, that must be the same code posted above, or if you don't include an explanation of the changes you did vs. the posted code.
Antonio
Re: List the files with in two datetime
Thanks Antonio. Problem is solved.
Re: List the files with in two datetime
@Aacini - Amen brother. I gave up long ago.
Re: List the files with in two datetime
+1Aacini wrote:I don't understand why you modify the posted code and then you ask why it don't works, or why you don't follow the indications given. It is difficult to help you when you can't follow very simple indications.
Re: List the files with in two datetime
The world has changed, hasn't it?
You help people freely from your spare time - and so often they don't reply.
Too often they post the same question on multiple forums - and so often they don't reply.
If asked for information - so often they don't give you any,
or argue that you don't need any information (which is ironic seeing they don't have the skills to solve their task, yet suddenly they are experts on what is needed to solve that same task).
Is it because the question-askers are younger people and so many of them don't know how to use the words please and thank you?
Or am I just an old fart and want them 'off my lawn'?
Just an idle comment here - it's a rhetorical question really.
You help people freely from your spare time - and so often they don't reply.
Too often they post the same question on multiple forums - and so often they don't reply.
If asked for information - so often they don't give you any,
or argue that you don't need any information (which is ironic seeing they don't have the skills to solve their task, yet suddenly they are experts on what is needed to solve that same task).
Is it because the question-askers are younger people and so many of them don't know how to use the words please and thank you?
Or am I just an old fart and want them 'off my lawn'?
Just an idle comment here - it's a rhetorical question really.
Re: List the files with in two datetime
foxidrive wrote:The world has changed, hasn't it?
You help people freely from your spare time - and so often they don't reply.
Too often they post the same question on multiple forums - and so often they don't reply.
If asked for information - so often they don't give you any,
or argue that you don't need any information (which is ironic seeing they don't have the skills to solve their task, yet suddenly they are experts on what is needed to solve that same task).
Is it because the question-askers are younger people and so many of them don't know how to use the words please and thank you?
Or am I just an old fart and want them 'off my lawn'?
Just an idle comment here - it's a rhetorical question really.
it is always the new hire or younger one in our workplace. gratitude is hidden in their dictionary but at the same time we learn again and again on humanity and fall into the same process afterwards