| 1. |
Solve : FOR COMMAND IN DOS BAT FILE? |
|
Answer» I am trying to use MULTIPLE FOR Commands to parse text in 2 text file. Keep all the variables active. Then do a move USING the variables to change the name by combining variables from both parse text file variables. move /y "d:\efiling\acknowledgements\%%L_%%M.%%N" "d:\efiling\acknowledgements\%%A_%%B_%%C_%%D-%%E-%%F %%G-%%H_%%I.%%N" ) since its contained within the nested FOR by the start of the ( from.... Quote for /f "tokens=1-3 delims=_.-: " %%L in (d:\efiling\inprocess\ackfilename.txt) do ( Note: This is untested... also be sure your using enable delayed expansion at the start of your batch. Someone else here might pick up on something else that is a problem as well with this. But unable to test this on work computer = uncertainty with what I gave you for corrections. I think what you really want is a one to one relationship with the two files. I am just assuming this. Otherwise if there is 9 files in your SAR File Name and 9 in your Ack File name you are really only getting 9 output files that are exactly the same as the last file name listed in your Ack File. Really need to see what is in your SAR and ACK Files.HERE IS A SAMPLE EXECUTION WITH ECHO ON. Maybe someone can see why I am getting this error. I parse two text files that each a a unique filename in them. Set each parsed field value to a unique local variable. Build a move to rename a file with parts of the two text files variable values now set to local variable. The problem come on the complex filename (It uses _ - and blank) in it filename. It parses OK. However, when I build the new filename I get added spaces, a missing hour field right after where a REAL space exists in the complex filename. For a rookie my eyes hurt and my brain know it has not enough experience. ANYONE I thank you in advance for the education on command language processing and solving this problem. -----------------------THE EXAMPLE FOLLOWS -------------------------------------------------- D:\EFILING\BIN>rem -- begin archive function -- D:\EFILING\BIN>dir /b d:\efiling\acknowledgements\FINCEN*.* 1>d:\efiling\inprocess\ackfilename.txt D:\EFILING\BIN>for /F "tokens=1-3 delims=_.-: " %L in (d:\efiling\inprocess\ackfilename.txt) do (copy /y "d:\efiling\acknowledgements\%L_%M.%N" d:\efiling\archive\%L_%M.%N ) D:\EFILING\BIN>(copy /y "d:\efiling\acknowledgements\FINCEN_20140130.ACKED" d:\efiling\archive\FINCEN_20140130.ACKED ) 1 file(s) copied. D:\EFILING\BIN>rem -- end archive function -- D:\EFILING\BIN>rem -- begin rename function -- D:\EFILING\BIN>for /F "tokens=1-3 delims=_." %L in (d:\efiling\inprocess\ackfilename.txt) do ( set FI=%L set DT=%M set TY=%N ) D:\EFILING\BIN>( set FI=FINCEN set DT=20140130 set TY=ACKED ) D:\EFILING\BIN>for /F "tokens=1-9 delims=_-: " %A in (d:\efiling\inprocess\sarfilename.txt) do ( set RCM=%A set SAR=%B set FRM=%C set MO=%D set DA=%E set YR=%F set HH=%G set MN=%H set ID=%I ) D:\EFILING\BIN>( set RCM=RCM set SAR=SAR set FRM=Form set MO=01 set DA=23 set YR=2014 set HH=15 set MN=08 set ID=TBSATEST ) D:\EFILING\BIN>move /y "d:\efiling\acknowledgements\FINCEN_20140130.ACKED" "d:\efiling\acknowledgements\RCM _SAR _Form _01 -23 -2014 -08 _TBSATEST.ACKED" 1 file(s) moved. D:\EFILING\BIN>rem -- end rename function -- * * * Quote from: tommyb on April 17, 2014, 11:15:36 AM For a rookie my eyes hurt and my brain know it has not enough experience. It might help to know that to assist the people reading here, it helps to give accurate and full information about what you want to do and also provide the text files (which you can attach to a post). Posting code that doesn't work is seldom helpful, when you don't also include the text being parsed and a full description of the task.Thank you foxidrive for your post. I apologize for not realizing the need for all information. Here are the filename I am parsing and the one line enter they each contain. ackfilename.txt contents: FINCEN_20140130.ACKED sarfilename.txt contents: RCM_SAR_Form_01-23-2014 15-08_TBSATEST I goal is a move command combining the parsed values of each filename. IF I KNOW THE FILENAMES THE FIX POSITION CODE WOULD BE: move /y "FINCEN_20140130.ACKED" "RCM_SAR_Form_01-23-2014 15-08_TBSATEST" Hope this provides reviewer with enough info. I do appreciate anyones opinion. Thank you, The DOS Rookie Test this: it will simply show you the command on the screen - so remove the echo keyword to make it work. Code: [Select]echo off for /f "usebackq delims=" %%a in ("ackfilename.txt") do ( for /f "usebackq delims=" %%b in ("sarfilename.txt") do ( echo move /y "%%a" "%%b" ) ) pause foxidrive, Thank you for that example. It was almost prefect. One little MOD and all is well. Now on to testing my nesting of FIND or FINDSTR. When I get frustrated again, as I expect will HAPPEN, I post. But your experience and advice was a big help. A BIG THANK YOU From, TommyBTalk about over complicating the initial problem.Squashman, What can you expect from a DOS Command language rookie. I am sorry you are . Wait until my next post. |
|