Sign in to follow this  
Followers 0
RazerM

Splitting Files

3 posts in this topic

I have this program, i have it set to split files into two pieces. How would i go about splitting it into 3 or more parts dynamically because the number of parts will be changeable

;===============================================================================
;
; Program Name: File Splitter
; Description:: Split and join files
; Requirement(s):  AutoIt Beta
; Author(s):       RazerM
;
;===============================================================================
;

#include <GUIConstants.au3>
#include <file.au3>
GUICreate("File Splitter", 600, 500)
$files = GUICtrlCreateInput("Click Browse", 70, 30, 520)
$fileu = GUICtrlCreateInput("Click Browse", 70, 60, 520)
$splitr = GUICtrlCreateRadio("Split", 10, 30)
GUICtrlSetState($splitr, $GUI_CHECKED)
GUICtrlSetState($fileu, $GUI_DISABLE)
$unsplitr = GUICtrlCreateRadio("Unsplit", 10, 60)
$browse = GUICtrlCreateButton("Browse", 10, 100, 80, 25)
$split = GUICtrlCreateButton("Split", 260, 150, 80, 25)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $browse
            If GUICtrlRead($splitr) = $GUI_CHECKED Then
                $s_file = FileOpenDialog("Choose File to split", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "All Files (*.*)")
                If $s_file <> "" Then GUICtrlSetData($files, $s_file)
            ElseIf GUICtrlRead($unsplitr) = $GUI_CHECKED Then
                $s_file = FileOpenDialog("Choose File to split", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "Split File (*.split)")
                If $s_file <> "" Then GUICtrlSetData($fileu, $s_file)
            EndIf
        Case $split
;~          $i_split = InputBox("Split", "Number of times to split")
            $i_split = 2
            If GUICtrlRead($split) == "Split" Then Split(GUICtrlRead($files), $i_split);NOTE $i_split is not used yet
            If GUICtrlRead($split) == "Unsplit" Then Unsplit(GUICtrlRead($fileu), $i_split)
        Case $splitr
            GUICtrlSetState($fileu, $GUI_DISABLE)   
            GUICtrlSetState($files, $GUI_ENABLE)
            GUICtrlSetData($split, "Split")
        Case $unsplitr
            GUICtrlSetState($files, $GUI_DISABLE)
            GUICtrlSetState($fileu, $GUI_ENABLE)
            GUICtrlSetData($split, "Unsplit")
    EndSwitch
WEnd

Func Unsplit($s_file, $i_split)
    If Not FileExists($s_file) Then
        MsgBox(48, "Error", "No file selected") 
        Return 0
    EndIf
    Dim $szDrive, $szDir, $szFName, $szExt
    $filesplit = _PathSplit($s_file, $szDrive, $szDir, $szFName, $szExt)
    If $filesplit[4] = ".split" Then
        $s_filep1 = IniRead($s_file, "Splits", "1", "Err")
        $s_filep2 = IniRead($s_file, "Splits", "2", "Err")
        $s_filep1 = FileRead(FileOpen($s_filep1, 0))
        $s_filep2 = FileRead(FileOpen($s_filep2, 0))
        FileWrite($filesplit[3], $s_filep1 & $s_filep2)
        MsgBox(0,"Done", "Files joined successfully")
        FileClose($s_filep1)
        FileClose($s_filep2)
    EndIf
EndFunc

Func Split($s_file, $i_split)
    If Not FileExists($s_file) Then
        MsgBox(48, "Error", "No file selected") 
        Return 0
    EndIf
    Dim $szDrive, $szDir, $szFName, $szExt
    $filesplit = _PathSplit($s_file, $szDrive, $szDir, $szFName, $szExt)
    $s_fileo = FileOpen($s_file, 0)
    $s_filec = FileRead($s_fileo)
    $s_filenl = StringLeft($s_filec, StringLen($s_filec)/2)
    $s_filenr = StringRight($s_filec, StringLen($s_filec)/2)
    DirCreate($filesplit[1] & $filesplit[2] & $filesplit[3])
    $npath = $filesplit[1] & $filesplit[2] & $filesplit[3] & "\" &  $filesplit[3] & $filesplit[4]
    FileDelete($npath & ".part1")
    FileDelete($npath & ".part1")
    FileDelete($npath & ".part2")
    FileWrite($npath & ".part1", $s_filenl)
    FileWrite($npath & ".part2", $s_filenr)
    IniWrite($npath & ".split", "Splits", "1", $filesplit[3] & $filesplit[4] & ".part1")
    IniWrite($npath & ".split", "Splits", "2", $filesplit[3] & $filesplit[4] & ".part2")
    MsgBox(0, "Done", "File has been split")
    FileClose($s_fileo)
EndFunc

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

Share this post


Link to post
Share on other sites



BladeMonkey did something like this I believe. Search his name in the titles for the Scripts and Scraps forum.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

FileRead($file, first 1/3 of total characters)

Store this in a file like .part1

FileRead($file, second 1/3 of total characters)

Store this in a file like .part2

FileRead($file, last 1/3 of total characters)

Store this in a file like .part3

I don't think this will require a lot more changes to your script

Edited by Manadar

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0