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

Posts 1–15 of 24 · Page 1 of 2
[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?
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
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".
If Not File.Exists(Path) Then
'whatever
End if
ok thanks man.

last question, how do you delete a folder and all its content inside?
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
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.
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
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.
flames for your code does it even read the file from my resources?
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.
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.
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 ??
how can you copy it? i never tried it.
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.
Posts 1–15 of 24 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us