ash5002 Posted October 9, 2011 Share Posted October 9, 2011 hi evry one i have a bout 2000 of vcf files that ther numper changed becus of the new numpring system in my contry so evry numper changed from numper start with 012 to 0122 numper start with 014 to 0114 numper start with 016 to 0106 numper start with 018 to 0108 numper start with 019 to 0109 and evry cvs file lok like BEGIN:VCARD VERSION:2.1 N;CHARSET=UTF-8:name TEL;CELL:0101290555 TEL;CELL:0144838934 TEL;CELL:0110757404 END:VCARD so i need to make an auto it screbt to change number in evry vcf file by the new sestem as exambel i want to make thes vcf file BEGIN:VCARD VERSION:2.1 N;CHARSET=UTF-8:name TEL;CELL:0101290555 TEL;CELL:0144838934 TEL;CELL:0110757404 END:VCARD to becam after modefing BEGIN:VCARD VERSION:2.1 N;CHARSET=UTF-8:name TEL;CELL:01001290555 TEL;CELL:01144838934 TEL;CELL:01110757404 END:VCARD so pleas any help Link to comment Share on other sites More sharing options...
ash5002 Posted October 9, 2011 Author Share Posted October 9, 2011 (edited) i made thes screbt and it work but if the vcf file contean more then a cell numper it just change the last numper expandcollapse popup$SearchFolder = "C:\as\" $SearchExt = "vcf" $SaveToFile = "C:\as\ahmed.csv" Dim $H_Begin, $H_Version, $H_Name, $H_TelWork, $H_FaxWork, $H_End, $H_edit $search = FileFindFirstFile($SearchFolder & "*." & $SearchExt) ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf $SaveFile = FileOpen( $SaveToFile, 2 ) $WriteLine = "Name" & "," & "PhoneNumber" & "," & "E-Mail" FileWriteLine($SaveFile,$WriteLine) While 1 $file = FileFindNextFile($search) If @error Then ExitLoop ;~ MsgBox(4096, "File:", $file) $VCARD_File = FileOpen($SearchFolder & $file, 0) ; Check if file opened for reading OK If $VCARD_File = -1 Then MsgBox(0, "Error", "Unable to open file." & $VCARD_File) Exit EndIf $H_Begin = "" $H_Version = "" $H_Name = "" $H_TelWork = "" $H_FaxWork = "" $H_End = "" $H_edit = "" ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($VCARD_File) If @error = -1 Then ExitLoop $Header = StringTrimRight($line, StringLen($line) - StringInStr($line,":") + 1 ) $result = StringTrimLeft($line,StringLen($Header) + 1 ) Select Case $header = "BEGIN" $H_Begin = $result Case $header = "VERSION" $H_Version = $result Case $header = "N;CHARSET=UTF-8" $H_Name = $result Case $header = "N" $H_Name = $result Case $header = "TEL;CELL" $H_TelWork = $result Case $header = "TEL;FAX" $H_FaxWork = $result Case $header = "END" $H_End = $result EndSelect Wend If $H_TelWork >=01560000000 Then $H_edit= $H_TelWork Else If $H_TelWork <0100000000 Then $H_edit= $H_TelWork Else If $H_TelWork >=01550000000 Then $H_edit= $H_TelWork-400000000 Else If $H_TelWork >=01520000000 Then $H_edit= $H_TelWork-400000000 Else If $H_TelWork >=01510000000 Then $H_edit= $H_TelWork-500000000 Else If $H_TelWork >=01500000000 Then $H_edit= $H_TelWork-300000000 Else If $H_TelWork >=0190000000 Then $H_edit= $H_TelWork+900000000 Else If $H_TelWork >=0180000000 Then $H_edit= $H_TelWork+1100000000 Else If $H_TelWork >=0170000000 Then $H_edit= $H_TelWork+1100000000 Else If $H_TelWork >=0160000000 Then $H_edit= $H_TelWork+900000000 Else If $H_TelWork >=0140000000 Then $H_edit= $H_TelWork+1000000000 Else If $H_TelWork >=0120000000 Then $H_edit= $H_TelWork+1100000000 Else If $H_TelWork >=0110000000 Then $H_edit= $H_TelWork+1000000000 Else If $H_TelWork >=0100000000 Then $H_edit= $H_TelWork+900000000 Else $H_edit= $H_TelWork EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf If $H_edit >=01560000000 Then $WriteLine = $H_Name & "," & $H_edit & "," FileWriteLine($SaveFile,$WriteLine) FileClose($VCARD_File) Else If $H_edit >=0100000000 Then $le = "C:\temp.txt" $le = FileOpen( $le, 2 ) $WriteLine = "0" & $H_edit FileWriteLine($le,$WriteLine) FileClose ( $le ) $l = "C:\temp.txt" $0H_edit = FileRead($l,FileGetSize($l)) $WriteLine = $H_Name & "," & $0H_edit & "," FileWriteLine($SaveFile,$WriteLine) FileClose($VCARD_File) $szText = FileRead($file,FileGetSize($file)) $szText = StringReplace($szText, $H_TelWork,$0H_edit) FileDelete($file) FileWrite($file,$szText) Else $WriteLine = $H_Name & "," & $H_edit & "," FileWriteLine($SaveFile,$WriteLine) EndIf EndIf WEnd ; Close the search handle FileClose ( $search ) FileClose ( $SaveFile ) Edited October 9, 2011 by ash5002 Link to comment Share on other sites More sharing options...
Developers Jos Posted October 9, 2011 Developers Share Posted October 9, 2011 Maybe something like the below script works. It will create a file with the same name suffixed by ".new". expandcollapse popup$SearchFolder = "C:\as\" $SearchExt = "vcf" ;~ $SaveToFile = "C:\as\ahmed.csv" Dim $H_Begin, $H_Version, $H_Name, $H_TelWork, $H_FaxWork, $H_End, $H_edit $search = FileFindFirstFile($SearchFolder & "*." & $SearchExt) ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $VCARD_File = FileOpen($SearchFolder & $file, 0) ; Check if file opened for reading OK If $VCARD_File = -1 Then MsgBox(0, "Error", "Unable to open file." & $VCARD_File) Exit EndIf ; Open new VCARD output file $VCARD_File_Out = FileOpen($SearchFolder & $file & ".new", 2) ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($VCARD_File) If @error = -1 Then ExitLoop ; check for TEL;CELL: lines If StringLeft($line,9) = "TEL;CELL:" Then $TelNr = StringMid($line,10) $TelNrPref = StringLeft($telnr,3) $TelNrSuf = StringMid($telnr,4) Switch $TelNrPref Case "010" $TelNrPref = "0100" Case "011" $TelNrPref = "0111" Case "012" $TelNrPref = "0122" Case "014" $TelNrPref = "0114" Case "016" $TelNrPref = "0106" Case "018" $TelNrPref = "0108" Case "019" $TelNrPref = "0109" Case Else ; nochange EndSwitch $line = "TEL;CELL:" & $TelNrPref & $TelNrSuf EndIf FileWriteLine($VCARD_File_Out,$line) WEnd FileClose($VCARD_File) FileClose($VCARD_File_Out) WEnd ; Close the search handle FileClose($search) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ash5002 Posted October 9, 2011 Author Share Posted October 9, 2011 Maybe something like the below script works. It will create a file with the same name suffixed by ".new". expandcollapse popup$SearchFolder = "C:\as\" $SearchExt = "vcf" ;~ $SaveToFile = "C:\as\ahmed.csv" Dim $H_Begin, $H_Version, $H_Name, $H_TelWork, $H_FaxWork, $H_End, $H_edit $search = FileFindFirstFile($SearchFolder & "*." & $SearchExt) ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $VCARD_File = FileOpen($SearchFolder & $file, 0) ; Check if file opened for reading OK If $VCARD_File = -1 Then MsgBox(0, "Error", "Unable to open file." & $VCARD_File) Exit EndIf ; Open new VCARD output file $VCARD_File_Out = FileOpen($SearchFolder & $file & ".new", 2) ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($VCARD_File) If @error = -1 Then ExitLoop ; check for TEL;CELL: lines If StringLeft($line,9) = "TEL;CELL:" Then $TelNr = StringMid($line,10) $TelNrPref = StringLeft($telnr,3) $TelNrSuf = StringMid($telnr,4) Switch $TelNrPref Case "010" $TelNrPref = "0100" Case "011" $TelNrPref = "0111" Case "012" $TelNrPref = "0122" Case "014" $TelNrPref = "0114" Case "016" $TelNrPref = "0106" Case "018" $TelNrPref = "0108" Case "019" $TelNrPref = "0109" Case Else ; nochange EndSwitch $line = "TEL;CELL:" & $TelNrPref & $TelNrSuf EndIf FileWriteLine($VCARD_File_Out,$line) WEnd FileClose($VCARD_File) FileClose($VCARD_File_Out) WEnd ; Close the search handle FileClose($search) realy ser i dont know how to thank you enougth you had do for me an agreat thing thanks alot Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now