Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    ppl2pass's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    804
    Reputation
    5
    Thanks
    111
    My Mood
    Amused

    [Vb.net] Write folder with files from resource to..

    How would you write a folder containing several files from resources to my usb using vb.net?

  2. #2
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    Code:
     Public Sub MoveFiles(ByVal sourcePath As String, ByVal DestinationPath As String)
            If (Directory.Exists(sourcePath)) Then
                For Each fName As String In Directory.GetFiles(sourcePath)
                    If File.Exists(fName) Then
                        Dim dFile As String = String.Empty
                        dFile = Path.GetFileName(fName)
                        Dim dFilePath As String = String.Empty
                        dFilePath = DestinationPath + dFile
                        File.Move(fName, dFilePath)
                    End If
                Next
            End If
        End Sub



  3. The Following User Says Thank You to Blubb1337 For This Useful Post:

    ppl2pass (05-24-2010)

  4. #3
    ppl2pass's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    804
    Reputation
    5
    Thanks
    111
    My Mood
    Amused
    alright thanks man.

    how can i check if a folder is already in there?

    so if a file called "private" is already in my documents, it will not make a new file called "private".

  5. #4
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    If Not File.Exists(Path) Then
    'whatever
    End if



  6. The Following User Says Thank You to Blubb1337 For This Useful Post:

    ppl2pass (05-24-2010)

  7. #5
    ppl2pass's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    804
    Reputation
    5
    Thanks
    111
    My Mood
    Amused
    ok thanks man.

    last question, how do you delete a folder and all its content inside?

  8. #6
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    Code:
    Public Sub DeleteFilesFromFolders(ByVal sourcePath As String)
            If (Directory.Exists(DirPath)) Then
                For Each fName As String In Directory.GetFiles(DirPath)
                    If File.Exists(fName) Then
                        File.Delete(fName)
                    End If
                Next
            End If
        End Sub



  9. #7
    ppl2pass's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    804
    Reputation
    5
    Thanks
    111
    My Mood
    Amused
    I need ur help guys.
    I have a slight problem.

    When i use this code
    Code:
      Dim RPath As String = Application.StartupPath & "\File.exe" 'File.exe will be a  temp name given to your exe, you can make it anything you want, or keep it as is.
     
    ' Will create the file with the given name
                Using CreateFile As New FileStream(RPath, FileMode.Create)
                    CreateFile.Write(My.Resources.YourResource, 0, My.Resources.YourResource.Length)
                End Using
    This would not work for .png or .xml files. It said something about a 1-dimensional array or something.

  10. #8
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by ppl2pass View Post
    I need ur help guys.
    I have a slight problem.

    When i use this code
    Code:
      Dim RPath As String = Application.StartupPath & "\File.exe" 'File.exe will be a  temp name given to your exe, you can make it anything you want, or keep it as is.
     
    ' Will create the file with the given name
                Using CreateFile As New FileStream(RPath, FileMode.Create)
                    CreateFile.Write(My.Resources.YourResource, 0, My.Resources.YourResource.Length)
                End Using
    This would not work for .png or .xml files. It said something about a 1-dimensional array or something.
    Try this:

    Dim RPath As String = Application.StartupPath & "\File.png"
    Dim i As System.Text.Encoding = System.Text.Encoding.ASCII
    Using CreateFile As New FileStream(RPath,FileMode.Create)
    CreateFile.Write(i.GetBytes(RPath),0,i.GetByteCoun t(RPath))
    End Using

  11. The Following User Says Thank You to Hassan For This Useful Post:

    ppl2pass (05-25-2010)

  12. #9
    Zoom's Avatar
    Join Date
    May 2009
    Gender
    male
    Location
    Your going on my 24/7 DDoS hit list.
    Posts
    8,552
    Reputation
    127
    Thanks
    5,970
    My Mood
    Happy
    Quote Originally Posted by ppl2pass View Post
    I need ur help guys.
    I have a slight problem.

    When i use this code
    Code:
      Dim RPath As String = Application.StartupPath & "\File.exe" 'File.exe will be a  temp name given to your exe, you can make it anything you want, or keep it as is.
     
    ' Will create the file with the given name
                Using CreateFile As New FileStream(RPath, FileMode.Create)
                    CreateFile.Write(My.Resources.YourResource, 0, My.Resources.YourResource.Length)
                End Using
    This would not work for .png or .xml files. It said something about a 1-dimensional array or something.
    [php] Dim myFile() As Byte = My.Resources.FilenameHere

    Dim fileData = New FileStream("\ProgramFiles\Filenamehere.png", FileMode.OpenOrCreate)
    Dim BW As New BinaryWriter(fileData)
    Try
    For bt As Integer = 0 To myFile.Length - 1
    BW.Write(myFile(bt))
    Next
    Catch ex As Exception
    MsgBox(ex)
    Finally
    fileData.Close()
    BW.Close()

    End Try[/php]

    Should work on any file.
    -Rest in peace leechers-

    Your PM box is 100% full.

  13. The Following User Says Thank You to Zoom For This Useful Post:

    ppl2pass (05-25-2010)

  14. #10
    ppl2pass's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    804
    Reputation
    5
    Thanks
    111
    My Mood
    Amused
    flames for your code does it even read the file from my resources?

  15. #11
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by ppl2pass View Post
    flames for your code does it even read the file from my resources?
    No, I just solved the encoding problem. I thought that it would write the file. But forgot about the source file. Anyways it can be done with this method too. As Hejsan's code solved your problem, I think there's no need for me to write that now.

  16. #12
    ppl2pass's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    804
    Reputation
    5
    Thanks
    111
    My Mood
    Amused
    hejan's code did not work. i still had the same problem... your code needs a bit of fixing but i dont know how to do it.

  17. #13
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by ppl2pass View Post
    hejan's code did not work. i still had the same problem... your code needs a bit of fixing but i dont know how to do it.
    OK, the first thing:

    Why you need to write the png file this way. Can't you directly copy the file to the specified target ? Or is there a problem in that ??

  18. #14
    ppl2pass's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    804
    Reputation
    5
    Thanks
    111
    My Mood
    Amused
    how can you copy it? i never tried it.

  19. #15
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by ppl2pass View Post
    how can you copy it? i never tried it.
    Dim FileToCopy As String = "C:\Documents and Settings\FlameXaber\My Documents\My Pictures\kristen\k1.jpg"

    Dim DestinationFile As String = Application.StartupPath & "\File.jpg"

    My.Computer.FileSystem.CopyFile(FileToCopy,Destina tionFile, True )


    This will copy the file the specified image to the specified location.

Page 1 of 2 12 LastLast

Similar Threads

  1. [Help] how to save dll from resources to temp folder.? [solved]
    By blackgaming in forum Visual Basic Programming
    Replies: 2
    Last Post: 08-14-2011, 12:27 AM
  2. Problem with paint.net and moding DTX files
    By dehpwner in forum Combat Arms Help
    Replies: 6
    Last Post: 06-10-2010, 03:09 AM
  3. Extract Audio files from BC2 folder
    By gano95 in forum Battlefield Bad Company 2 (BFBC2) Hacks
    Replies: 3
    Last Post: 03-31-2010, 06:15 PM
  4. [SOURCE CODE]Write File To Disk From Resources[VB.NET]
    By ajvpot in forum Combat Arms Hack Coding / Programming / Source Code
    Replies: 2
    Last Post: 03-30-2010, 08:54 PM
  5. Replies: 13
    Last Post: 08-08-2007, 03:03 AM