Click here to Skip to main content
6,292,426 members and growing! (10,121 online)
Email Password   helpLost your password?
Languages » VB.NET » Applications     Beginner License: The Code Project Open License (CPOL)

Folder Coder

By Buffalloy

A way to convert a folder into a file...
VB (VB 7.x, VB 8.0, VB 9.0, VB 6)
Posted:11 Dec 2007
Updated:11 Dec 2007
Views:16,165
Bookmarked:25 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
2 votes for this article.
Popularity: 1.00 Rating: 3.33 out of 5

1

2
1 vote, 50.0%
3
1 vote, 50.0%
4

5
Screenshot - hlp_small.jpg

The beginning...

Well, it's all my sisters' fault... she told me she'd give me an 'Independent' sign if I make her an app that locks folders... so what could I do...?

THE CODE

Basically, this is the code that I use to code a selected folder...

     Private Sub Code()
        Try
            'prepares the writer to write

            Dim fs As New FileStream("C:\Mitio\Locked.log",
                FileMode.Append)
            Dim sw As New StreamWriter(fs)
            ' sets the progressbar max value

            ProgressBar1.Maximum = lb.Items.Count

            For Each obj As Object In lb.Items
                Dim name As String = My.Computer.FileSystem.GetName(
                    obj.ToString)
                Dim bytes() As Byte
                ' reads the bytes from the specified fie & stores them in

                ' the array

                bytes = My.Computer.FileSystem.ReadAllBytes(obj.ToString)

                Dim bn As Integer = bytes.Length ' gets the length of the bytes

                ' appends the bytes of the array to the newly created

                ' Locked.locked file

                My.Computer.FileSystem.WriteAllBytes(
                    "C:\Mitio\Locked.Locked", bytes, True) 

                'writes the name of the file and the length of the

                'binaries in it

                sw.WriteLine(bn.ToString + "*" + name) 

                ProgressBar1.Value += 1 ' performs a step


            Next
            lb.Items.Clear() 'clears the list


            sw.Close() 'closes the writer


            fs.Close() 'and the file


            ProgressBar1.Value = 0 ' resets the  progressbar


        Catch ex As Exception
            ' if anything happens, you will be gently informed :D

            MsgBox(ex.Message)

        End Try
    End Sub

And I think there's not much into it...

And this is the code to DEcode the folder

private sub Decode()
Try
            Dim bf As New FileStream("C:\Mitio\Locked.locked", 
                FileMode.Open, FileAccess.Read, FileShare.Inheritable)
            Dim br As BinaryReader ' opens the LOCKED file


            Dim sf As New FileStream("C:\Mitio\Locked.log", 
                FileMode.Open)
            Dim sr As New StreamReader(sf) ' Opens the LOG file


            Dim s As String = sr.ReadLine
            lb.Items.Add(CObj(s))
            While Not s Is "" ' adds all files from the LOG file


                s = sr.ReadLine
                If s = "" Then Exit While
                lb.Items.Add(CObj(s))
            End While
            Label1.Text = lb.Items.Count
            sr.Close() ' closes the LOG file


            sf.Close()
            Dim j As Integer = 0
            br = New BinaryReader(bf)
            Dim i As Integer = 0
            pb2.Maximum = Label1.Text
            For Each obj As Object In lb.Items
                pb2.Value += 1 ' performs step


                Dim ss() As String = obj.ToString.Split("*") 'spit 


                Dim bytes As Integer = ss(0) 'the binaries


                Dim name As String = (ss(1)) 'and the filename 

                'creates a new file with the name from the list

                Dim bf1 As New FileStream(txtOut.Text + name, FileMode.Append, 
                    FileAccess.Write, FileShare.Write)
 
                Dim bw As New BinaryWriter(bf1)
                Try
                    For i = 1 To CInt(bytes)
                        'writes the number of bytes for each file

                        bw.Write(br.ReadByte()) 

                    Next
                Catch ex As Exception
                    MsgBox(ex.Message) ' again if something happens...


                End Try
                bw.Close() 'close...


                bf1.Close()
            Next
            br.Close() 'and close again


            bf.Close()
            lb.Items.Clear() 'clears the list again


            pb2.Value = 0 ' resets the progressbar


        Catch ex As Exception
            MsgBox(ex.Message) 'ohh


        End Try
end sub

Afterall

It's not finished properly yet but I'll keep intouch...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Buffalloy


Member
I was born in Plovdiv, Bulgaria in1991.

I began programming two years ago, and the firs language I encountered was Pascal. I got to know it very well, but five or six months ago I took up Visual Basic. I still study it, and as far as I can see I have a lot to do, befor I can develop serious apps and games.It's hard to study programming when you are in highschool... Pitty...
Dimitar Todorov, BG.
Location: Bulgaria Bulgaria

Other popular VB.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Layout  Per page   
 Msgs 1 to 7 of 7 (Total in Forum: 7) (Refresh)FirstPrevNext
GeneralGood PinmemberMember 461989520:34 27 Jan '09  
GeneralHmm Pinsupporterpeterchen10:07 11 Dec '07  
GeneralEver heard of ZIP files? Pinmemberfuzzylintman6:59 11 Dec '07  
GeneralRe: Ever heard of ZIP files? Pinmemberjconwell7:55 11 Dec '07  
GeneralRe: Ever heard of ZIP files? PinmemberMichael Sync16:39 12 Dec '07  
GeneralRe: Ever heard of ZIP files? Pinmemberjconwell6:28 3 Jan '08  
GeneralExplanations I had to do before... PinmemberBuffalloy2:05 18 Jan '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 11 Dec 2007
Editor: Sean Ewington
Copyright 2007 by Buffalloy
Everything else Copyright © CodeProject, 1999-2009
Web15 | Advertise on the Code Project