![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-09-25 18:13 |
47,813 topics / 349,918 posts / today 0 new / 48,275 members |
| DOS批处理 & 脚本技术(批处理室) » How to write P processing that meets this function |
| Printable Version 2,692 / 17 |
| Floor1 joshualaw | Posted 2007-08-07 16:20 |
| 初级用户 Posts 62 Credits 132 | |
|
In the process of data processing (C:\123\Many.TXT files), I urgently need a P processing that can achieve the following functions. Please help!
1> The third line is the same 2> The first line is greater than or equal to 3> The second line is greater than. The.txt files are moved to C:\456, as follows. B.txt should be moved. Note: (The characters to be compared in the first, second, and third lines are all variables, and within the same line, they are separated by the TAB key) The following are part of the contents of two.txt files. A.txt Date 06/29/07 Time 08:16:26 Serial # ML07300010JEB Script file 2820.scr Station GXHCDG02 PASSED CAPTURED TARS DATA LABEL VALUE AssyNum W10130544 GDS_ErrTmp 0x00 WaterBeforeReload 0x00b5 HVDC_LO_Byte 0x0136 GDS_ErrTmp 0x00 B.txt Date 06/30/07 Time 08:19:30 Serial # ML07300010JEB Script file 2820.scr Station GXHCDG02 PASSED CAPTURED TARS DATA LABEL VALUE AssyNum W10130544 GDS_ErrTmp 0x00 WaterBeforeReload 0x00b5 HVDC_LO_Byte 0x0136 GDS_ErrTmp 0x00 [ Last edited by joshualaw on 2007-8-7 at 09:50 PM ] |
|
| Floor2 joshualaw | Posted 2007-08-07 17:46 |
| 初级用户 Posts 62 Credits 132 | |
Originally posted by 26933062 at 2007-8-7 05:34 PM: No, the object is between any Txt files in C:\123\, first compare the third line, only after they are completely the same, then compare the first line and the second line, |
|
| Floor3 joshualaw | Posted 2007-08-07 21:46 |
| 初级用户 Posts 62 Credits 132 | |
Originally posted by 26933062 at 2007-8-7 06:03 PM: ---》The last 07 is the year, to avoid confusion, I wrote the date format of the first line here, mm/dd/yy Sorry, maybe I didn't express it well. Please take another look at my colored reply. [ Last edited by joshualaw on 2007-8-7 at 09:48 PM ] |
|
| Floor4 joshualaw | Posted 2007-08-08 11:11 |
| 初级用户 Posts 62 Credits 132 | |
|
First of course I'm grateful for your enthusiasm, but it still can't run now. The errors are as follows,
Now the problem is, if there are more than 3 files with the same content in the third line. How to judge the content of the first and second lines? For example: 4.txt, 5.txt and 6.txt After comparing 4.txt and 5.txt, 5.txt meets your requirements and will be moved. Then what about 6.txt? Do we still need to compare it with 4.txt? Yes, as long as the third line is the same, compare the first and second lines two by two. In short, move out those with the same third line, the first line greater than or equal to, and the second line greater than (the date and time are closer to the most recent), Attachments nodefine.jpg (8.86 KiB) |
|
| Floor5 joshualaw | Posted 2007-08-08 19:38 |
| 初级用户 Posts 62 Credits 132 | |
|
What I understand is: The first line is the date, the second line is the time. When comparing, if the first line is greater, there's no need to compare the second line anymore, right? If the first line is equal, then compare the second line, is that so?
-->Yes There's another question: If there are three or more files with the third line the same, and the first lines of content are 07/20/07, 07/25/07, 07/30/07 respectively, what should be done? Move the file with 07/30/07, then do the remaining two need to be compared again? -->Then move 07/25/07. If both are 07/20/07, then look at which has the larger second line time and move that one Now I have attached this folder, which has 10 TXT files. The third lines of the three files 14103806.txt, 45678912.txt, and 123455675.txt are all the same 1》When P processes the first run, move 14103806.txt first because its first line date is 06/15/07, 2》When P processes the second run, move 123455675.txt again because their first line dates are the same, both 06/14/07, but the second line time 10:37:20 >10:36:48 The above English means that the variable - + -1 is not defined. Now I hope you can understand it more clearly. First, thank you! [ Last edited by joshualaw on 2007-8-10 at 11:05 PM ] |
|
| Floor6 26933062 | Posted 2007-08-08 22:56 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
Finally got it......
The above code is okay. The problem is that you said that each line is separated by tabs, but in fact, the space in front of the # in your third line is a space, not a tab, and the problem is here. The file you uploaded is moved by this batch file: 14103806.txt and 123455675.txt files, no need to run twice. Is this the effect you want? The following code was tested successfully on my side. It can handle file names with spaces. .] [ Last edited by 26933062 on 2007-8-9 at 04:47 AM ] |
|
| Floor7 island008 | Posted 2007-08-08 22:56 |
| 新手上路 Posts 4 Credits 9 | |
| Floor8 26933062 | Posted 2007-08-08 23:05 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
The part at the end of the code is for judging the date and time. It feels a bit messy. I would like to ask all the experts if there is a simpler way to judge.
For example, judge which date is larger between 05/30/2007 and 07/20/2007? Judge which time is earlier between 18:20:08 and 09:05:12? I split the date with for to judge. For the time part, it is directly judged. For example: if 18:20:08 gtr 09:05:12 echo ok I wonder if it will go wrong in some cases. |
|
| Floor9 joshualaw | Posted 2007-08-09 08:05 |
| 初级用户 Posts 62 Credits 132 | |
Originally posted by 26933062 at 2007-8-8 10:56 PM: Hard work, amazing. All functions can be realized. First, thank you. But there is a small requirement as follows. Let's see if it can be done. Finally, it's done...... The above code is okay. The problem is that you said each line is separated by a tab, but in fact, the space before the # in the third line is not a tab, and the problem lies here. The file you uploaded is moved by this batch file as 14103806.txt and 123455675.txt, which is moved at one time, without running twice. That is to say, after running the batch file, all files with the same third line content and the earliest first line date (if the dates are the same, the earliest second line time) will be moved. Only one file is left. Is this the effect? ----->Can the files moved for the first time, second time, third time..... be moved to different folders under c:\456 respectively? For example: C:\456\1\14103806.txt, C:\456\2\123455675.txt. If it can be done like this, this processing will be more perfect and convenient for processing. Thank you. |
|
| Floor10 qzwqzw | Posted 2007-08-09 09:06 |
| 银牌会员 Posts 636 Credits 2,343 | |
|
26楼的代码,可以将整理格式后的两个日期分别放入两个变量中进行比较就可以了,完全没有必要对年月日分别进行比较。Special format date comparison: Just unify them into one format in advance and then compare. For example, the code on floor 6: You can put the two sorted dates into two variables respectively for comparison, and there is absolutely no need to compare the year, month and day respectively.
|
|
| Floor11 26933062 | Posted 2007-08-09 09:59 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
It should be okay, but it's not in chronological order. Is that acceptable?
Then you mean you have to create as many folders in c:\123 as the number of files moved? Need to think about it... No time now, I'll think about it when I have time. |
|
| Floor12 26933062 | Posted 2007-08-09 10:04 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
Brother on floor 10, I used the following method to judge the date and made a mistake. Is the method wrong?
@echo off set a=05/30/2006 set b=05/25/2007 if %a% lss %b% (echo aaa 小) else echo aaa 大 pause |
|
| Floor13 joshualaw | Posted 2007-08-13 20:46 |
| 初级用户 Posts 62 Credits 132 | |
|
Brother 26933062:
Can you take some time to improve it? Just meet either of the following two conditions. 1》Move the files moved each time into different folders under C:\456, for example: c:\456\11\contains the files moved for the first time c:\456\22\contains the files moved for the second time c:\456\33\contains the files moved for the third time, at most moved three times 2》Move only one each time. Thanks! [ Last edited by joshualaw on 2007-8-13 at 08:48 PM ] |
|
| Floor14 joshualaw | Posted 2007-08-16 07:56 |
| 初级用户 Posts 62 Credits 132 | |
|
Brother 26933062:
Can you please take some time to improve it so that each time only one is moved over? Thanks! |
|
| Floor15 qzwqzw | Posted 2007-08-16 08:32 |
| 银牌会员 Posts 636 Credits 2,343 | |
|
Reply to floor 12
That's because your date format is not uniformly arranged correctly. Arrange it in the order of year, month, and day, and there will be no problem when comparing. Actually, this is comparing strings, not numeric strings, because there are invalid numbers (such as /) in the strings being compared, but the achieved effect is similar. For safety, you can add 0 prefixes for alignment to months and days. Time comparison is also similar, as long as it is ensured that the larger time unit comes first. |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |