Hi all, here a very easy lwebcode free script to split file in C#
// calls example
...
int iSplittedFileSize = 1024 * 8;MergeFile(@"C:\script\", iSplittedFileSize, @"C:\LwebCodeMergeFile\");
...
public static void MergeFile(string inputfoldername1, string SaveFileFolder)
{
string[] tmpfiles = Directory.GetFiles(inputfoldername1, "*.tmp");
FileStream outPutFile = null;
string PrevFileName = "";
foreach (string tempFile in tmpfiles)
{
string fileName = Path.GetFileNameWithoutExtension(tempFile);
string baseFileName = fileName.Substring(0, fileName.IndexOf(Convert.ToChar(".")));
string extension = Path.GetExtension(fileName);
if (!PrevFileName.Equals(baseFileName))
{
if (outPutFile != null)
{
outPutFile.Flush();
outPutFile.Close();
}
outPutFile = new FileStream(SaveFileFolder + "\\" + baseFileName + extension, FileMode.OpenOrCreate, FileAccess.Write);
}
int bytesRead = 0;
byte[] buffer = new byte[1024];
FileStream inputTempFile = new FileStream(tempFile, FileMode.OpenOrCreate, FileAccess.Read);
while ((bytesRead = inputTempFile.Read(buffer, 0, 1024)) > 0)
outPutFile.Write(buffer, 0, bytesRead);
inputTempFile.Close();
PrevFileName = baseFileName;
}
}
Hope you like it ;)
Showing posts with label path. Show all posts
Showing posts with label path. Show all posts
Thursday, 20 July 2017
Friday, 30 June 2017
C# Split File
Hi all, here a very easy lwebcode free script to split file in C#
// calls example
...
int iSplittedFileSize = 1024 * 8;
SplitFile(@"C:\script\lwebcode.bak", iSplittedFileSize, @"C:\script\");
...
public static void SplitFile(string inputFile, int chunkSize, string path)
{
const int BUFFER_SIZE = 20 * 1024; //2 Kb for each file
byte[] buffer = new byte[BUFFER_SIZE];
string baseFileName = Path.GetFileNameWithoutExtension(inputFile);
string Extension = Path.GetExtension(inputFile);
using (Stream input = File.OpenRead(inputFile))
{
int index = 0;
while (input.Position < input.Length)
{
string sFinalName = path + "\\" + baseFileName + "." + index.ToString().PadLeft(5, Convert.ToChar("0")) + Extension + ".tmp";
using (Stream output = File.Create(sFinalName))
{
int remaining = chunkSize, bytesRead;
while (remaining > 0 && (bytesRead = input.Read(buffer, 0,
Math.Min(remaining, BUFFER_SIZE))) > 0)
{
output.Write(buffer, 0, bytesRead);
remaining -= bytesRead;
}
}
index++;
System.Threading.Thread.Sleep(500);
}
}
}
Hope you like it ;)
// calls example
...
int iSplittedFileSize = 1024 * 8;
SplitFile(@"C:\script\lwebcode.bak", iSplittedFileSize, @"C:\script\");
...
public static void SplitFile(string inputFile, int chunkSize, string path)
{
const int BUFFER_SIZE = 20 * 1024; //2 Kb for each file
byte[] buffer = new byte[BUFFER_SIZE];
string baseFileName = Path.GetFileNameWithoutExtension(inputFile);
string Extension = Path.GetExtension(inputFile);
using (Stream input = File.OpenRead(inputFile))
{
int index = 0;
while (input.Position < input.Length)
{
string sFinalName = path + "\\" + baseFileName + "." + index.ToString().PadLeft(5, Convert.ToChar("0")) + Extension + ".tmp";
using (Stream output = File.Create(sFinalName))
{
int remaining = chunkSize, bytesRead;
while (remaining > 0 && (bytesRead = input.Read(buffer, 0,
Math.Min(remaining, BUFFER_SIZE))) > 0)
{
output.Write(buffer, 0, bytesRead);
remaining -= bytesRead;
}
}
index++;
System.Threading.Thread.Sleep(500);
}
}
}
Hope you like it ;)
Monday, 23 January 2017
VBA get Word Excel Outlook Path without reference and declaration, late binding
Hi All, here an example to know Word, Excel or Outlook .exe path, without adding reference to object
Here the function, copy and paste it to vba module
Here the function, copy and paste it to vba module
Function GetProgFilesPath(ByVal sExecutable As String) As String
On Error GoTo Err_Exit
Dim obj As Object
Select Case LCase(sExecutable)
Case "winword.exe", "word.exe"
Set obj = CreateObject("Word.Application")
Case "excel.exe"
Set obj = CreateObject("Excel.Application")
Case "outlook.exe"
Set obj = CreateObject("Outlook.Application")
Case Else
MsgBox "Not Managed" & sExecutable, vbInformation
Exit Function
End Select
GetProgFilesPath = obj.path
Set obj = Nothing
Exit_Exit:
Exit Function
Err_Exit:
MsgBox "Err:GetProgFilesPath=" & Err.Description
Resume Exit_Exit
End Function
Subscribe to:
Posts (Atom)