Saved Bookmarks
| 1. |
Solve : Emilware....This is your post? |
|
Answer» I tried responding to this PM however Emilware's mailbox is full. <sigh> hey Sidewinder Emil, I prefer not to answer PM, but rather try and help out on the public boards. This gives even the casual user a chance to learn from the posting. Quote Please i spent 3 day on this i get nowhere It got you here and we're somewhere. Nowhere is to the left! Code: [Select]echo on echo in progress setlocal enabledelayedexpansion for /f "tokens=* delims=" %%x in ('dir /a:-d /s /b C:\temp\*.txt') do ( for /f "tokens=* delims=" %%i in (%%x) do ( set input=%%i set input=!input:bob=emil! set input=!input:smith=mark! set input=!input:peter=kevin! echo !input! >> "%%x.chg" ) ren "%%x" "%%~nxx.old" ren "%%x.chg" "%%~nxx" ) The snippet labels the original file with an old extension and labels the NEW file with the original name. Good luck. thank you for your help. this works great and sorry about sending u PM. i'm new to this. like i said this works but i have an other problem. when new file gets created and the lines are being copied for some reason it skips lines starting with ;FOLD and ;ENDFOLD .Is there a way to FIX that? this is example of the file that i'm tring to change. ;FOLD ; *** Timer Start SW ***;%{PE}%R 4.1.16,%MKUKATPBASIS,%CCOMMENT,%VNORMAL,%P 2:*** Timer Start SW *** ;ENDFOLD $TIMER[3]=0 $TIMER_STOP[3]=FALSE ;FOLD ; **********************;%{PE}%R 4.1.16,%MKUKATPBASIS,%CCOMMENT,%VNORMAL,%P 2:********************** ;ENDFOLD ;FOLD PTP lap110 CONT Vel= 100 % PDAT11 Tool[15]:Car-Zero Base[6]:car-0 extTCP;%{PE}%R 4.1.15,%MKUKATPBASIS,%CMOVE,%VPTP,%P 1:PTP, 2:lap110, 3:C_PTP, 5:100, 7:PDAT11 $BWDSTART = FALSE PDAT_ACT=PPDAT11 BAS(#PTP_DAT) FDAT_ACT=Flap110 BAS(#FRAMES) BAS(#VEL_PTP,100) PTP Xlap110 C_PTP ;ENDFOLD ;FOLD PTP sw164w11625013 PDAT26 SPOT Gun= 2 RETR CLS ACTIVE= 1 Tool[15]:Car-Zero Base[6]:car-0 extTCP;%{PE}%R 4.1.11,%MKUKATPSPOT,%CSPOT,%VPTP,%P 1:PTP, 2:sw164w11625013, 3:, 5:100, 7:PDAT26, 10:2, 12:#FIRST, 14:#CLO, 16:0, 18:1, 20:0, 22:0, 24:1, 25:NORMAL $BWDSTART = TRUE PDAT_ACT=PPDAT26 BAS(#PTP_DAT) FDAT_ACT=Fsw164w11625013 BAS(#FRAMES) BAS(#VEL_PTP,PPDAT26.VEL) S_ACT.GUN=2 S_ACT.PAIR=SDEFAULT.PAIR S_ACT.RETR=#CLO S_ACT.CLO_TM=1 S_ACT.PGNO1=11625013 S_ACT.PGNO2=SDEFAULT.PGNO2 S_ACT.PRESS1=SDEFAULT.PRESS1 S_ACT.PRESS2=SDEFAULT.PRESS2 S_READY=FALSE PTP Xsw164w11625013 USERSPOT(#SPOT, S_ACT) WAIT FOR S_READY ;ENDFOLD The sw164w11625013 must be change to sw164w1100625013. I must insert 00 after 11. If there is a way just to modify original file by inserting 00 after sw164w11 insted of creating a new file, then that would work too. I tried writing VBS but with out wildcard i cant get it to open and change all files with extension .SRC and .DAT in the folder. Code: [Select]Const ForReading = 1 Const ForWriting = 2 Const FileIn = "C:\transfer\test.txt" Const FileOut = "C:\transfer\test.txt" '<== Change to prevent overwrite of original file Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(FileIn, ForReading) strText = objFile.ReadAll objFile.Close strNewText = Replace(strText, "bob", "emil") Set objFile = objFSO.OpenTextFile(FileOut, ForWriting) objFile.WriteLine strNewText objFile.Close PLease help me if u can. thanks By default FOR /f skips lines with a semicolon at the start. For them to be read, a different end of line (eol) character must be assigned in the delims block. Choose a suitable character that does not appear in the lines you wish to process. In this example I have used the character for /f "[email protected] tokens=* delims=" %%i in (%%x) do ( Quote I tried writing VBS but with out wildcard i cant get it to open and change all files with extension .SRC and .DAT in the folder. This should eliminate your need for a wildcard: Code: [Select]Const ForReading = 1 Const ForWriting = 2 Set objFSO = CreateObject("Scripting.FileSystemObject") Set f = objFSO.GetFolder("c:\transfer") Set fc = f.Files For Each fs In fc If objFSO.GetExtensionName(fs) = "SRC" Or objFSO.GetExtensionName(fs) = "DAT" Then Set objFile = objFSO.OpenTextFile(fs.Path, ForReading) strOldText = objFile.ReadAll objFile.Close strNewText = Replace(strOldText, "bob", "emil", 1, -1 ,1) 'First replace use strOldtext strNewText = Replace(strNewText, "smith", "mark", 1, -1, 1) 'Subsequent replace use strNewText strNewText = Replace(strNewText, "peter", "kevin", 1, -1, 1) Set objFile = objFSO.OpenTextFile(fs.Path, ForWriting) objFile.WriteLine strNewText objFile.Close Set objFile = objFSO.CreateTextFile(fs.Path & ".old") objFile.WriteLine strOldText objFile.Close End If Next The replace function is case insensitive. Same situation applies as with the batch code: original file gets labeled with an old extension; Changed file has same label as original file. Good luck. Thanks SIDEWINDER YOU REALY KNOW YOUR STUFF This works great Its lot faster than batch. This is the best search and replace. Thanks |
|