Sinisterly
[VB.Net] System.IO.File Functions - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Visual Basic & .NET Framework (https://sinister.ly/Forum-Visual-Basic-NET-Framework)
+--- Thread: [VB.Net] System.IO.File Functions (/Thread-VB-Net-System-IO-File-Functions)



[VB.Net] System.IO.File Functions - 1234hotmaster - 02-20-2011

IO.File.AppendText & IO.File.AppendAllText & IO.File.CreateText & IO.File.WriteAllText & IO.File.WriteAllLines & IO.File.WriteAllBytes


Explanation: These functions are used to create TextFiles or write bytes.

Example:
Code:
IO.File.AppendText("C:\text.txt") IO.File.AppendAllText("C:\text.txt", Textbox1.text) IO.File.CreateText("C:\Text.txt") IO.File.WriteAllText("C:\test.txt", Textbox1.text) IO.File.WriteAllLines("C:\text.txt", Textbox1.text) IO.File.WriteAllBytes("C:\file.exe", Nothing)


Format:
Code:
IO.File.AppendText(Path) IO.File.AppendAllText(Path, Contents) IO.File.CreateText(Path) IO.File.WriteAllText(Path, Contents) IO.File.WriteAllLines(Path, Contents) IO.File.WriteAllBytes(Path, Byte)







IO.File.Copy


Explanation: This function is used to copy files.

Example:
Code:
IO.File.Copy(Application.ExecutablePath, "C:\copied.exe")


Format:
Code:
IO.File.Copy(SourceFileName, Destinationfilename)





IO.File.Create


Explanation: Creates a file of any format.

Example:
Code:
IO.File.Create("C:\new.exe")


Format:
Code:
IO.File.Create(Path)







IO.File.Delete


Explanation: Deletes an existing file.

Example:
Code:
IO.File.Delete("C:\file.exe")


Format:
Code:
IO.File.Delete(Path)







IO.File.Exists


Explanation: Gets a boolean ( True or False ) value whether the file exists or no.

Example:
Code:
If IO.File.Exists("C:\file.exe") = True Then MsgBox("File Exists") Else MsgBox("File Does not Exist") End If


Format:
Code:
IO.File.Exists(Path)







IO.File.GetAttributes


Explanation: Gets the value of a file's Attribute.

Example:
Code:
MsgBox(IO.File.GetAttributes("C:\hidden.exe"))


Format:
Code:
IO.File.GetAttributes(Path)







IO.File.GetCreationTime & IO.File.GetCreationTimeUtc & IO.File.GetLastAccessTime & IO.File.GetLastAccessTimeUtc & IO.File.GetLastWriteTime


Explanation: Gets values of a file's Creation time, which the time a file is created and its date for utc ones. And gets its last editing time or creation time or when its last opened.

Example:
Code:
IO.File.GetCreationTime("C:\file.exe") IO.File.GetCreationTimeUtc("C:\file.exe") IO.File.GetLastAccessTime("C:\file.exe") IO.File.GetLastAccessTimeUtc("C:\file.exe") IO.File.GetLastWriteTime("C:\file.exe")


Format:
Code:
IO.File.GetCreationTime(Path) IO.File.GetCreationTimeUtc(Path) IO.File.GetLastAccessTime(Path) IO.File.GetLastAccessTimeUtc(Path) IO.File.GetLastWriteTime(Path)







IO.File.Move


Explanation: Moves a file to a new directory. Same like Cut and Paste.

Example:
Code:
IO.File.Move(Application.ExecutablePath, "C:\moved.exe")


Format:
Code:
IO.File.Move(SourceFileName, Destinationfilename)







IO.File.Open & IO.File.OpenRead & IO.File.OpenText & IO.File.OpenWrite


Explanation: Open's a file for either reading or writing to it.

Example:
Code:
IO.File.Open("C:\file.exe", IO.FileMode.Open) Textbox1.text = IO.File.OpenRead("C:\text.txt") Textbox1.text = IO.File.OpenText("C:\text.txt") IO.File.OpenWrite("C:\text.txt")


Format:
Code:
IO.File.Open(Path, Mode) IO.File.OpenRead(Path) IO.File.OpenText(Path) IO.File.OpenWrite(Path)







IO.File.ReadAllBytes & IO.File.ReadAllLines & IO.File.ReadAllText


Explanation: Opens a file to read its byte array or all Textlines or its text.

Example:
Code:
Dim aByteArray As Byte() = IO.File.ReadAllBytes("C:\file.exe") Dim aStringArray As String() = IO.File.ReadAllLines("C:\text.txt") Dim aString As String = IO.File.ReadAllText("C:\text.txt")


Format:
Code:
IO.File.ReadAllBytes(Path) IO.File.ReadAllLines(Path) IO.File.ReadAllText(Path)







IO.File.Replace


Explanation: Rewrites a existing file and makes a backup of it.

Example:
Code:
IO.File.Replace(Application.ExecutablePath, "C:\copy.exe", "C:\backup.exe")


Format:
Code:
IO.File.Replace(SourceFileName, DestinationFileName, DestinationBackupFileName)






IO.File.SetAttributes


Explanation: Sets or changes a file's attribute.

Example:
Code:
IO.File.SetAttributes("C:\Unhidden.exe", FileAttribute.Hidden)


Format:
Code:
IO.File.SetAttributes(Path, FileAttributes)







IO.File.SetCreationTime & IO.File.SetCreationTimeUtc & IO.File.SetLastAccessTime & IO.File.SetLastAccessTimeUtc & IO.File.SetLastWriteTime


Explanation: Can set a file's creation date, the same date and time it got created or its last opened date and time or its last Edited time. Very useful for virus makers to fool the opener to think the binded file's creation date is like 2 years ago.

Example:
Code:
IO.File.SetCreationTime("C:\file.exe", Date.Today) IO.File.SetCreationTimeUtc("C:\file.exe", Date.UtcNow) IO.File.SetLastAccessTime("C:\file.exe", Date.Now) IO.File.SetLastAccessTimeUtc("C:\file.exe", Date.Now) IO.File.SetLastWriteTime("C:\file.exe", Date.Now)


Format:
Code:
IO.File.SetCreationTime(Path, Date) IO.File.SetCreationTimeUtc(Path, Date) IO.File.SetLastAccessTime(Path, Date) IO.File.SetLastAccessTimeUtc(Path, Date) IO.File.SetLastWriteTime(Path, Date)








File.Attributes: The Properties of files. The VB Attributes are:
  • FileAttribute.Archive
  • FileAttribute.Directory
  • FileAttribute.Hidden
  • FileAttribute.Normal
  • FileAttribute.ReadOnly
  • FileAttribute.System
  • FileAttribute.Volume



Boolean: The Conditions that can connect codes. There are known booleans as:
  • True ( Saying something is True )
  • False ( Saying something is False )
  • = ( Saying something is equal to another Code )
  • <> ( Saying something is not equal to another Code )
  • < ( Saying something is bigger then the Code's value )
  • > ( Saying something is smaller then the Code's Value )



Examples:
Code:
If IO.File.Exists("C:\file.exe") = true then If IO.File.Exists("C:\file.exe") = false then If integer = 1 = true then If integer <> 1 = true then If integer < 1 = true then If integer > 1 = true then












Writed by 1234hotmaster. Please don't leech or give credits and source if you share.

Have a Great day Smile



RE: [VB.Net] System.IO.File Functions - 1llusion - 02-20-2011

Code:
Imports System.IO
Tongue

Nice guide!!! I really like it!!!

btw, in the boolean, you use double checking, which is not necessary Smile
Spoiler:
Code:
If integer = 1 = true then
The code will be read:
Quote:If integer is 1 = true = true then

Boolean is set as "true" by default Smile

That means, its more simple to use:
Code:
If integer = 1 then
it will be read:
Quote:If integer is 1 = true then

However, for boolean false you will need it Smile

so:
Code:
If integer = 1 = false then
will be read:
Quote:If integer is 1 = false then

Smile



RE: [VB.Net] System.IO.File Functions - 1234hotmaster - 02-20-2011

well, still even double checking works Tongue

Glad you liked it. More guides to come Smile


RE: [VB.Net] System.IO.File Functions - 1llusion - 02-20-2011

(02-20-2011, 05:20 PM)1234hotmaster Wrote: well, still even double checking works Tongue

Glad you liked it. More guides to come Smile

Yeh, but it slows down the process a little bit. And also more words = more complicated Tongue

Looking forward for more great guides!!!!!!!


RE: [VB.Net] System.IO.File Functions - Coder-san - 02-20-2011

Nice thread, keep it up. Smile

You can show the return values more clearly like:

Code:
Dim aByteArray As Byte() = IO.File.ReadAllBytes("C:\file.exe") Dim aStringArray As String() = IO.File.ReadAllLines("C:\text.txt") Dim aString As String = IO.File.ReadAllText("C:\text.txt")



RE: [VB.Net] System.IO.File Functions - 1234hotmaster - 02-20-2011

Tnx for the examples. Edited Smile


RE: [VB.Net] System.IO.File Functions - Livelife93 - 02-21-2011

Nice things you got goin. good tut.


RE: [VB.Net] System.IO.File Functions - 9toes - 02-27-2011

thanks man ! awesome !
this must be transfered in the important thread category .


RE: [VB.Net] System.IO.File Functions - jnoon - 02-09-2014

What will be the source file name