- /*
- * Created by SharpDevelop.
- * User: hidalgo emmanuel
- * Date: 24/04/2008
- * Time: 12:20
- *
- * To change this template use Tools | Options | Coding | Edit Standard Headers.
- */
-
- using System;
- using System.IO;
- using System.Collections;
-
- namespace delete_tag_utf8_bom_win
- {
- /// <summary>
- /// Description of ScanUtf8Bom.
- /// </summary>
- public class ScanUtf8Bom
- {
- public string sLogFichiers = "";
- private string[] _oExtension;
-
- public ScanUtf8Bom( string[] oExtensions ){
- this._oExtension = oExtensions;
- }
-
- public void ScanFolder( DirectoryInfo oDirectory ){
- foreach( FileInfo oFileInfo in oDirectory.GetFiles() ){
- string sExtension = oFileInfo.Extension;
- if( sExtension.Length > 1 && sExtension.Substring( 0, 1 ) == "." )
- sExtension = sExtension.Substring( 1 );
- string sOkExtension = Array.Find( this._oExtension, delegate ( string sExt ) { return sExt == sExtension; } );
- if( sOkExtension != null && this.FileIsBOM( oFileInfo.FullName ) )
- this.DeleteTagBom( oFileInfo.FullName );
- }
- foreach( DirectoryInfo oDirectoryChild in oDirectory.GetDirectories() )
- if( oDirectoryChild.Name != ".svn" )
- this.ScanFolder( oDirectoryChild );
- }
-
- public bool FileIsBOM( string sFile ){
- byte[] oData = new Byte[ 3 ];
- byte[] oBom = new Byte[ 3 ];
- oBom[ 0 ] = 239;// -> i
- oBom[ 1 ] = 187;// -> »
- oBom[ 2 ] = 191;// -> ¿
-
- FileStream oFileStream = new FileStream( sFile, FileMode.Open );
- oFileStream.Read( oData, 0, 3 );
-
- for( int i = 0; i < oData.Length; i++ )
- if( oData[ i ] != oBom[ i ] )
- return false;
-
- oFileStream.Close();
-
- return true;
- }
-
- public void DeleteTagBom( string sFile ){
- this.sLogFichiers += "delete tag in : " + sFile + "\r\n";
-
- FileInfo oFileInfo = new FileInfo( sFile );
- byte[] oData = new byte[ oFileInfo.Length ];
-
- FileStream oFileStream = new FileStream( sFile, FileMode.Open );
- oFileStream.Read( oData, 0, (int)oFileInfo.Length );
- oFileStream.Close();
-
- File.Delete( sFile );
-
- oFileStream = new FileStream( sFile, FileMode.Create );
- oFileStream.Write( oData, 3, oData.Length - 3 );
- oFileStream.Close();
- }
- }
- }
/*
* Created by SharpDevelop.
* User: hidalgo emmanuel
* Date: 24/04/2008
* Time: 12:20
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.IO;
using System.Collections;
namespace delete_tag_utf8_bom_win
{
/// <summary>
/// Description of ScanUtf8Bom.
/// </summary>
public class ScanUtf8Bom
{
public string sLogFichiers = "";
private string[] _oExtension;
public ScanUtf8Bom( string[] oExtensions ){
this._oExtension = oExtensions;
}
public void ScanFolder( DirectoryInfo oDirectory ){
foreach( FileInfo oFileInfo in oDirectory.GetFiles() ){
string sExtension = oFileInfo.Extension;
if( sExtension.Length > 1 && sExtension.Substring( 0, 1 ) == "." )
sExtension = sExtension.Substring( 1 );
string sOkExtension = Array.Find( this._oExtension, delegate ( string sExt ) { return sExt == sExtension; } );
if( sOkExtension != null && this.FileIsBOM( oFileInfo.FullName ) )
this.DeleteTagBom( oFileInfo.FullName );
}
foreach( DirectoryInfo oDirectoryChild in oDirectory.GetDirectories() )
if( oDirectoryChild.Name != ".svn" )
this.ScanFolder( oDirectoryChild );
}
public bool FileIsBOM( string sFile ){
byte[] oData = new Byte[ 3 ];
byte[] oBom = new Byte[ 3 ];
oBom[ 0 ] = 239;// -> i
oBom[ 1 ] = 187;// -> »
oBom[ 2 ] = 191;// -> ¿
FileStream oFileStream = new FileStream( sFile, FileMode.Open );
oFileStream.Read( oData, 0, 3 );
for( int i = 0; i < oData.Length; i++ )
if( oData[ i ] != oBom[ i ] )
return false;
oFileStream.Close();
return true;
}
public void DeleteTagBom( string sFile ){
this.sLogFichiers += "delete tag in : " + sFile + "\r\n";
FileInfo oFileInfo = new FileInfo( sFile );
byte[] oData = new byte[ oFileInfo.Length ];
FileStream oFileStream = new FileStream( sFile, FileMode.Open );
oFileStream.Read( oData, 0, (int)oFileInfo.Length );
oFileStream.Close();
File.Delete( sFile );
oFileStream = new FileStream( sFile, FileMode.Create );
oFileStream.Write( oData, 3, oData.Length - 3 );
oFileStream.Close();
}
}
}