VB 写的文件分割工具,还蛮好用的。附上源码

VB 写的文件分割工具,还蛮好用的。附上源码,第1张

概述VERSION 5.00 Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "Comdlg32.ocx" Begin VB.Form frmMain    BorderStyle     =   1  ´Fixed Single    Caption         =   "文件分割工具"    ClientHeight    = 

VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "Comdlg32.ocx"
Begin VB.Form frmMain
borderStyle = 1 ´Fixed Single
Caption = "文件分割工具"
ClIEntHeight = 2880
ClIEntleft = 45
ClIEnttop = 330
ClIEntWIDth = 3795
KeyPrevIEw = -1 ´True
linktopic = "Form1"
Maxbutton = 0 ´False
Minbutton = 0 ´False
ScaleHeight = 2880
ScaleWIDth = 3795
StartUpposition = 3 ´windows Default
Begin VB.TextBox txtCode
Backcolor = &H8000000F&
Height = 3945
left = 30
Locked = -1 ´True
Multiline = -1 ´True
Scrollbars = 2 ´Vertical
TabIndex = 13
top = 2910
Visible = 0 ´False
WIDth = 3705
End
Begin VB.Frame frmContainer
Height = 2865
left = 0
TabIndex = 0
top = 30
WIDth = 3735
Begin VB.Commandbutton cmdUnit
Caption = "合 并"
Enabled = 0 ´False
Height = 345
left = 1890
TabIndex = 11
top = 2400
WIDth = 945
End
Begin VB.Commandbutton cmdsplit
Caption = "分 割"
Height = 345
left = 120
TabIndex = 10
top = 2400
WIDth = 945
End
Begin VB.Frame fraSelect
Caption = "选项:"
Height = 585
left = 90
TabIndex = 7
top = 1710
WIDth = 3555
Begin VB.ComboBox cmbSplitSize
Height = 315
left = 990
Style = 2 ´Dropdown List
TabIndex = 12
top = 210
WIDth = 1305
End
Begin VB.Optionbutton optUnit
Caption = "合并"
Height = 315
left = 2640
TabIndex = 9
top = 180
WIDth = 825
End
Begin VB.Optionbutton optSplit
Caption = "分割"
Height = 255
left = 240
TabIndex = 8
top = 240
Value = -1 ´True
WIDth = 1305
End
End
Begin VB.Commandbutton cmdFind
Caption = "选择文件夹"
Height = 345
left = 2550
TabIndex = 6
top = 1170
WIDth = 1125
End
Begin VB.Commandbutton cmdselectfile
Caption = "选择文件"
Height = 345
left = 2550
TabIndex = 5
top = 480
WIDth = 1125
End
Begin VB.TextBox txtSourcefile
Height = 315
left = 90
TabIndex = 2
top = 480
WIDth = 2355
End
Begin VB.TextBox txtObject
Height = 315
left = 90
TabIndex = 1
top = 1170
WIDth = 2355
End
Begin VB.Label lblCaption
Caption = "选择的源文件:"
Height = 285
Index = 0
left = 90
TabIndex = 4
top = 210
WIDth = 1515
End
Begin VB.Label lblCaption
Caption = "选择的目标文件夹:"
Height = 285
Index = 1
left = 90
TabIndex = 3
top = 900
WIDth = 1815
End
End
Begin MSComDlg.CommonDialog cdgFindfile
left = 3060
top = 90
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
End
Attribute VB_name = "frmMain"
Attribute VB_GlobalnameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredID = True
Attribute VB_Exposed = False
Option Explicit

Private Declare Function SHbrowseForFolder _
lib "shell32.dll" Alias "SHbrowseForFolderA" _
(lpbrowseInfo As broWSEINFO) As Long

Private Declare Function SHGetPathFromIDList _
lib "shell32.dll" _
(ByVal pIDl As Long,_
pszPath As String) As Long

Private Type broWSEINFO
hOwner As Long
pIDlRoot As Long
pszdisplayname As String
lpszTitle As String
ulFlage As Long
lpfn As Long
lparam As Long
iImage As Long
End Type

Private fnum As Integer

Private Function ShowDir(MehWnd As Long,_
DirPath As String,_
Optional Title As String = "请选择文件夹:",_
Optional flage As Long = &H1,_
Optional DirID As Long) As Long
Dim BI As broWSEINFO
Dim TempID As Long
Dim TempStr As String

TempStr = String$(255,Chr$(0))
With BI
.hOwner = MehWnd
.pIDlRoot = 0
.lpszTitle = Title + Chr$(0)
.ulFlage = flage

End With

TempID = SHbrowseForFolder(BI)
DirID = TempID

If SHGetPathFromIDList(ByVal TempID,ByVal TempStr) Then
DirPath = left$(TempStr,InStr(TempStr,Chr$(0)) - 1)
ShowDir = -1
Else
ShowDir = 0
End If

End Function


Private Function Operatefile(ByVal vfile As String,_
ByVal vSplit As Boolean _
) As Long
Dim ItemSize As Long
Dim fileSize As Long
Dim ReadSize As Long
Dim i As Long
Dim vArr() As Byte
Dim fnum2 As Integer
Dim filename As String
Dim Splitfiles As Long

If vSplit Then
´合并
ItemSize = cmbSplitSize.ItemData(cmbSplitSize.ListIndex)
´取得当前选择的分析尺寸.

ReDim vArr(1 To ItemSize) As Byte
´重定义缓冲数组.

filename = Right(vfile,InStr(StrReverse(vfile),"/") - 1)
´取得文件名.

fnum = Freefile()
Open vfile For Binary As fnum
fileSize = LOF(fnum)
´取得文件大小

While fileSize > 0
ReadSize = ItemSize
If ReadSize > fileSize Then
´如果文件所剩余大小比当前选择的小,就使用剩余大小.
ReadSize = fileSize
ReDim vArr(1 To ReadSize)
End If

Get fnum,i * ItemSize + 1,vArr
i = i + 1

fnum2 = Freefile()

Open Trim(txtObject.Text) & "/" & Trim(Str(i)) & "_" & filename For Binary As fnum2
´ If i = 1 Then Put fnum2,Splitfiles
Put fnum2,vArr
Close fnum2

fileSize = fileSize - ReadSize
´文件总大小减少.
Wend
Close fnum

MsgBox "分割成功.",vbOKCancel,"提示信息"
Else
´分割
Dim Findfile As Boolean
Dim filePath As String
´是否还有后继文件标志
Findfile = True
filename = Right(vfile,"/") - 3)
filePath = left(vfile,Len(vfile) - InStr(StrReverse(vfile),"/") + 1)
´求原始文件名称

fnum = Freefile()
Open Trim(txtObject.Text) & "/" & filename For Binary As fnum


While Findfile
fnum2 = Freefile()

Open vfile For Binary As fnum2
fileSize = LOF(fnum2)
If fileSize > 0 Then
ReDim vArr(1 To fileSize)

Get fnum2,1,vArr
Put fnum,vArr
Close fnum2
End If
i = i + 1
If Dir(Trim(Str(i + 1)) & "_" & filename) = "" Then Findfile = False
vfile = filePath & Trim(Str(i)) & "_" & filename
Wend

Close fnum

MsgBox "合并成功.",vbOKOnly,"提示信息"
End If
End Function


Private Sub cmdFind_Click()
Dim TmpPath As String

ShowDir Me.hWnd,TmpPath
If Trim(TmpPath) <> "" Then
txtObject.Text = Trim(TmpPath)
End If
End Sub

Private Sub cmdselectfile_Click()
If optSplit.Value Then
cdgFindfile.Filter = "全部文件(*.*)|*.*|文本文件(*.txt)|*.txt"
Else
cdgFindfile.Filter = "全部文件(1_*.*)|1_*.*"
End If
cdgFindfile.DialogTitle = "选择要分割的文件"
cdgFindfile.ShowOpen
If Trim(cdgFindfile.filename) <> "" Then
txtSourcefile.Text = cdgFindfile.filename
End If
End Sub

Private Sub cmdsplit_Click()
If Trim(txtSourcefile.Text) = "" Then MsgBox "请选择要分割的文件."
Operatefile txtSourcefile.Text,True
End Sub

Private Sub cmdUnit_Click()
Operatefile txtSourcefile.Text,False
End Sub

Private Sub Form_KeyDown(KeyCode As Integer,Shift As Integer)
If Shift = 6 Then
If Not txtCode.Visible Then
frmMain.Height = 7260
txtCode.Visible = True
Else
frmMain.Height = 3300
txtCode.Visible = False
End If
End If
End Sub

Private Sub Form_Load()
cmbSplitSize.AddItem "1.4M"
cmbSplitSize.ItemData(0) = 1400000
cmbSplitSize.AddItem "1.0M"
cmbSplitSize.ItemData(1) = 1000000
cmbSplitSize.AddItem "0.8M"
cmbSplitSize.ItemData(2) = 800000
cmbSplitSize.AddItem "0.6M"
cmbSplitSize.ItemData(3) = 600000
cmbSplitSize.AddItem "0.3M"
cmbSplitSize.ItemData(4) = 400000
cmbSplitSize.AddItem "0.1M"
cmbSplitSize.ItemData(5) = 100000
cmbSplitSize.ListIndex = 1
End Sub

Private Sub optSplit_Click()
cmdstart.Enabled = True
cmbSplitSize.Enabled = True
cmdOk.Enabled = False
End Sub

Private Sub optUnit_Click() cmdstart.Enabled = False cmbSplitSize.Enabled = False cmdOk.Enabled = TrueEnd Sub

总结

以上是内存溢出为你收集整理的VB 写的文件分割工具,还蛮好用的。附上源码全部内容,希望文章能够帮你解决VB 写的文件分割工具,还蛮好用的。附上源码所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1294117.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-10
下一篇 2022-06-10

发表评论

登录后才能评论

评论列表(0条)

保存