Move newest XML files by reading first lines

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
ShadowThief
Expert
Posts: 1163
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Move newest XML files by reading first lines

#16 Post by ShadowThief » 01 May 2017 22:27

No, that's actually the ideal format for the +D flag

Code: Select all

/D    date          Selects files with a last modified date greater
                    than or equal to (+), or less than or equal to
                    (-), the specified date using the
                    "MM/dd/yyyy" format; or selects files with a
                    last modified date greater than or equal to (+)
                    the current date plus "dd" days, or less than or
                    equal to (-) the current date minus "dd" days. A
                    valid "dd" number of days can be any number in
                    the range of 0 - 32768.
                    "+" is taken as default sign if not specified.

elzooilogico
Posts: 128
Joined: 23 May 2016 15:39
Location: Spain

Re: Move newest XML files by reading first lines

#17 Post by elzooilogico » 02 May 2017 02:05

The date format is not relevant as all commands are supposed to run under the same localization context. So both forfiles and cmd know my date format is dd/mm/yyyy in my system, and they should know your date format is mm/dd/yyyy.

This is working here (win 8.1 spanish),
forfiles /P "." /M "*.xml" /D "+%date%">"fileList.txt"

I cannot test with your date format, I only can think about removing quotes from /D "+%date%"
forfiles /P "." /M "*.xml" /D +%date%>"fileList.txt"

(but seems silly to me, as both ways gives me the same result)

penpen
Expert
Posts: 1996
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Move newest XML files by reading first lines

#18 Post by penpen » 02 May 2017 07:08

ZayaMia wrote:ERROR: Invalid argument/option - '05/02/2017'.
That's unexpected (to me):
I always assumed forfiles should use the same date format as the local system.

But as i see in the docu part quoted by ShadowThief, you could also use 0 instead of the actual date, so please test the above batch with this changed "forfiles line":

Code: Select all

forfiles /P "." /M "*.xml" /D +0 /C "cmd /c for %%a in (@file) do @(echo(%%~a") | >"fileList.txt" findstr /V "^$"


penpen

ShadowThief
Expert
Posts: 1163
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Move newest XML files by reading first lines

#19 Post by ShadowThief » 02 May 2017 08:01

You know what it probably is? In some localizations, %date% includes the day of the week.

C:\Users\hawk>echo %date%
Tue 05/02/2017

penpen
Expert
Posts: 1996
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Move newest XML files by reading first lines

#20 Post by penpen » 02 May 2017 08:37

ShadowThief wrote:C:\Users\hawk>echo %date%
Tue 05/02/2017
I've never seen any windows version with a default short date format ("HKCU\Control Panel\International\sShortDate")
other than "m/d/yy", "dd/mm/yyyy", or "dd.mm.yyyy", so just out of curiosity:
If this is the default value, then may i ask which windows version and localization are you running?


penpen

ShadowThief
Expert
Posts: 1163
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Move newest XML files by reading first lines

#21 Post by ShadowThief » 02 May 2017 09:47

Yeah, I haven't changed anything.

Windows 10 Pro 64-bit, English (United States)

Code: Select all

 INFO.BAT version 1.4
--------------------------------------------------------------------------------
Windows version        :  Microsoft Windows [Version 10.0.14393]
Product name           :  Windows 10 Pro, 64 bit
Performance indicators :  Processor Cores: 4      Visible RAM: 16691964 kilobytes

Date/Time format       :  (mm/dd/yy)  Tue 05/02/2017  11:46:52.13
__APPDIR__             :  C:\WINDOWS\system32\
ComSpec                :  C:\WINDOWS\system32\cmd.exe
PathExt                :  .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
Extensions             :  system: Enabled   user: Enabled
Delayed expansion      :  system: Disabled  user: Disabled
Locale name            :  en-US       Code Pages: OEM  437    ANSI 1252
DIR  format            :  04/30/2017  02:41 PM    17,179,869,184 pagefile.sys
Permissions            :  Elevated Admin=No, Admin group=Yes

                          Missing from the tool collection:  debug


I'm in the same time zone as Dave Benham; I wonder if he gets similar results.

ZayaMia
Posts: 14
Joined: 25 Apr 2017 02:54

Re: Move newest XML files by reading first lines

#22 Post by ZayaMia » 03 May 2017 00:00

It still won't work for me. gives me the same errors as mentioned before.

those XML files are also dated with their time, if it matters...

e.g: 5/3/2017 11:20 AM.

If there is more data , which might help, I'd gladly provide.

penpen
Expert
Posts: 1996
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Move newest XML files by reading first lines

#23 Post by penpen » 03 May 2017 04:39

ZayaMia wrote:It still won't work for me. gives me the same errors as mentioned before.
What exactly did you test (another date format instead of "%date%", or the "0" - see my second last post)?
(Note that "0" worked for all systems i tested.)

Some testworthy date formats (if using "0" doesn't work) for todays date (only the values in doublequotes):
(- "05/03/2017")
- "05-03-2017"
- "05.03.2017"
- "03/05/2017"
- "03-05-2017"
- "03.05.2017"


penpen

ZayaMia
Posts: 14
Joined: 25 Apr 2017 02:54

Re: Move newest XML files by reading first lines

#24 Post by ZayaMia » 03 May 2017 20:23

Yes I saw your last post.

cmd gives me for date: 05/04/2017

penpen
Expert
Posts: 1996
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Move newest XML files by reading first lines

#25 Post by penpen » 04 May 2017 05:06

My intention was to let you test which dfate format is working with forfiles, not to get the date format your system is using:
Both date formats obviously doesn't macth, else my above script suggestion would have worked.

So please put this "test.bat" into an empty directory and execute it:

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion
>"TestFile.xml" echo("TestFile.xml"
forfiles /M "*.xml" /D +0
pause

Expected result:

Code: Select all

"TestFile.xml"
Drücken Sie eine beliebige Taste . . .

If you get the expected result, then just use "0" instead of "%date%" in the forfile command (0 == actual date == today).
(If you see another result, then try the date formats i suggested, until one is working.)


penpen

ZayaMia
Posts: 14
Joined: 25 Apr 2017 02:54

Re: Move newest XML files by reading first lines

#26 Post by ZayaMia » 04 May 2017 20:41

Wow, I feel really relived.

It works perfeclty now.

Guess it was really my own mistake. Didn't read the instuctions clearly :oops:

Thank you so much for your support ! Highly , highly appreciated !

Post Reply