Имя пользователя:
Пароль:
 

Показать сообщение отдельно

Ветеран


Сообщения: 27449
Благодарности: 8088

Профиль | Отправить PM | Цитировать


Re:Flex, на WSH, пробуйте:
читать дальше »
Код: Выделить весь код
Option Explicit

Dim lngPartSize
Dim intMaxPartCount

Dim strSourceFile

Dim objRegExp
Dim objMatch

Dim strContent

Dim intPartNumber
Dim lngPos
Dim strPartFileName


If WScript.Arguments.Count = 1 Then
	With WScript.CreateObject("Scripting.FileSystemObject")
		strSourceFile = .GetAbsolutePathName(WScript.Arguments.Item(0))
		
		lngPartSize     = 500 * 2^10 ' 500Kb
		intMaxPartCount = 999        ' Не более 999 частей
		
		If .FileExists(strSourceFile) Then
			Set objRegExp = WScript.CreateObject("VBScript.RegExp")
			
			With objRegExp
				.Global  = True
				
				.Pattern = "[\s\S]{" & CStr(lngPartSize) & "}[\s\S]*?\r\n\r\n"
			End With
			
			With .OpenTextFile(strSourceFile)
				strContent = .ReadAll()
				.Close
			End With
			
			intPartNumber = 0
			lngPos        = 0
			
			If objRegExp.Test(strContent) Then
				For Each objMatch In objRegExp.Execute(strContent)
					intPartNumber = intPartNumber + 1
					strPartFileName = .BuildPath(.GetParentFolderName(strSourceFile), .GetBaseName(strSourceFile) & ".part" & Right(String(Len(CStr(intMaxPartCount)), "0") & CStr(intPartNumber), Len(CStr(intMaxPartCount))) & "." & .GetExtensionName(strSourceFile))
					
					With .CreateTextFile(strPartFileName, True)
						.Write objMatch.Value
						.Close
					End With
					
					lngPos = objMatch.FirstIndex + objMatch.Length
					WScript.Echo FormatPercent(lngPos / Len(strContent), 1) & ": Write file [" & strPartFileName & "]: " & CStr(objMatch.Length) & " b."
				Next
			End If
			
			intPartNumber = intPartNumber + 1
			strPartFileName = .BuildPath(.GetParentFolderName(strSourceFile), .GetBaseName(strSourceFile) & ".part" & Right(String(Len(CStr(intMaxPartCount)), "0") & CStr(intPartNumber), Len(CStr(intMaxPartCount))) & "." & .GetExtensionName(strSourceFile))
			
			With .CreateTextFile(strPartFileName, True)
				.Write Right(strContent, Len(strContent) - lngPos)
				.Close
			End With
			
			WScript.Echo FormatPercent(1, 1) & ": Write file [" & strPartFileName & "]: " & CStr(Len(strContent) - lngPos) & " b."
		Else
			WScript.Echo "Source file [" & strSourceFile & "] not found."
		End If
	End With
Else
	WScript.Echo "Usage: cscript.exe //nologo " & WScript.ScriptName & " <Source file>"
End If

WScript.Quit 0


Возможный результат (для некоего случая с «lngPartSize = 30» и файлом «0001.txt»):
читать дальше »
Код: Выделить весь код
8.9%: Write file [E:\Песочница\0289\0001.part001.txt]: 62 b.
18.0%: Write file [E:\Песочница\0289\0001.part002.txt]: 64 b.
25.9%: Write file [E:\Песочница\0289\0001.part003.txt]: 55 b.
33.8%: Write file [E:\Песочница\0289\0001.part004.txt]: 55 b.
41.6%: Write file [E:\Песочница\0289\0001.part005.txt]: 55 b.
53.4%: Write file [E:\Песочница\0289\0001.part006.txt]: 82 b.
65.1%: Write file [E:\Песочница\0289\0001.part007.txt]: 82 b.
76.8%: Write file [E:\Песочница\0289\0001.part008.txt]: 82 b.
88.6%: Write file [E:\Песочница\0289\0001.part009.txt]: 82 b.
100.0%: Write file [E:\Песочница\0289\0001.part010.txt]: 80 b.

Последний раз редактировалось Iska, 07-07-2013 в 19:51.

Это сообщение посчитали полезным следующие участники:

Отправлено: 19:44, 07-07-2013 | #5