Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Created by SharpDevelop & Notepad++
- * Date: 2019.08.21.
- * Time: 10:13
- *
- * 0x0A byte-ok cseréje 0x20 byte-ra
- *
- */
- using System;
- using System.IO;
- using System.Collections.Generic;
- namespace kill_LF
- {
- class Program
- {
- public static void Main(string[] args)
- {
- if ( args.Length == 2 )
- {
- Console.WriteLine(args[0]+" "+args[1]);
- // Environment.CurrentDirectory
- string[] exes = Directory.GetFiles(args[0], args[1]);
- foreach (string file in exes)
- {
- Console.WriteLine(Path.GetFileName(file));
- DoIt(file);
- }
- } else {
- System.Console.WriteLine(@"Fordítás: 'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe kill_LF.cs'");
- System.Console.WriteLine( "Használat: kill_LF.exe paraméter-1 paraméter-2");
- System.Console.WriteLine( " Paraméterek:\n\t1. útvonal (aktuális könyvtár: '.')\n\t2. fájlnév (*.dat)\n");
- }
- Console.Write("\nPress any key to continue . . . ");
- Console.ReadKey(true);
- } // Main()
- public static void DoIt(String filename)
- {
- /* Too long way for read...
- FileInfo f = new FileInfo(filename);
- byte[] buffer = new byte[f.Length];
- using (FileStream stream = new FileStream(f.FullName, FileMode.Open))
- {
- using (BinaryReader reader = new BinaryReader(stream))
- {
- if ( buffer.Length != reader.Read(buffer,0,buffer.Length) )
- {
- System.Console.WriteLine("Hiba törpént...?");
- }
- }
- }
- */
- // The fast way for read...
- byte[] buffer = File.ReadAllBytes(filename);
- File.WriteAllBytes(filename.Replace(".dat",".dat.old"), buffer);
- int rownum = 0;
- var lfCount = new List<Int32>();
- int lastItem = 0;
- //byte[] newbuffer = new byte[f.Length];
- for(int i=1; i<buffer.Length; i++)
- {
- if ( buffer[i-1]==13 && buffer[i]==10 )
- {
- rownum++;
- }
- if ( buffer[i-1]!=13 && buffer[i]==10 )
- {
- lfCount.Add(i);
- buffer[i] = 32;
- //newbuffer[i] = 32;
- System.Console.WriteLine("\t"+lfCount.Count+". érintett sor száma: "+rownum+", karakterszám: "+i+" ("+(i-lastItem)+")");
- lastItem = i;
- continue;
- } else {
- //newbuffer[i-lfCount.Count] = buffer[i];
- }
- }
- if ( lfCount.Count > 0 )
- {
- /* Too long way for write...
- using (FileStream stream = new FileStream(filename.Replace(".dat","_new.dat"),FileMode.Create))
- {
- using (BinaryWriter writer = new BinaryWriter(stream))
- {
- //buffer = newbuffer;
- writer.Write(buffer);
- writer.Close();
- } // using
- } // using
- */
- // The fast way for write...
- File.WriteAllBytes(filename, buffer);
- } else {
- File.Delete(filename.Replace(".dat",".dat.old"));
- } // if
- } // DoIt()
- } // class
- } // namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement