breaking a large file into smaller files

vb6 Grenada
  • 14 years ago
    i want to break a large file into smaller files each of size 2KB.i want to give the file names as 1.txt,2.txt,3.txt etc how can i do this
  • 14 years ago
    In general 1 KB is about 1024 characters. What you can do is get every 2048 characters from the main file and then save that data into a new file, using an index variable to count how many files have been made and name the file that.
  • 14 years ago

    problem is how to name the files.for example i have a variable "index"  , i want to craete a file ,of name as that of the contents of variable "index"

  • 14 years ago

    Try something like this, you will have to format the outout to the files and play around with the number of characters in each text file:


    Private Sub Command1_Click()

    'Path/filename of original file
    Open "C:/break/original.txt" For Input As #1

    'Variables
    Dim intLength As Double         'Length of files
    Dim intCounter As Integer       'Counter for unique filenames
    Dim strLine As String              'One line from master file
    Dim strOutput As String          'Line of output

    'reset vars
    intLength = 0
    intCounter = 1
    strOutput = ""

    'Loop till EOF(master)
    While Not EOF(1)
        
        'Get next line
        Line Input #1, strLine
        strOutput = strOutput & strLine
        
        'record length of line
        intLength = intLength & Len(strLine)
        If intLength > 1024 Then

            'If number of characters in output file exceeds a certain number then produce output
            Open "C:/break/" & intCounter & ".txt" For Output As #2
            Print #2, strOutput
            Close #2

            'Reset vars
            intLength = 0
            intCounter = intCounter + 1
            strOutput = ""
        End If
    Wend
    End Sub








































Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perl - The only language that looks the same before and after RSA encryption.” - Keith Bostic