Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can I move the file to a different folder

Status
Not open for further replies.

josie2007

Technical User
Apr 14, 2007
90
US
how can I move the file that I copied over from the server to a different folder before I apply any formatting to it. I would like to add some extension to it just to differentiate and not to overwrite form the previous one copied over to this folder.

this is the file copied from the server
NewEbsFiles = "W:\IO\qebsfnam\pass2ebs"

I would like to move it to c:\expedite\pass2ebs folder


Private Sub GetEbsFiles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetEbsFiles.Click
Dim NewEbsFiles As String
Dim OldEbsFiles As String
Dim p1 As Integer
Dim TextLength As Integer
Dim TextFound As String = ""
Dim FileString As String = ""
Dim AllLines As String = ""

NewEbsFiles = "W:\IO\qebsfnam\pass2ebs"
OldEbsFiles = "C:\Expedite\gen\pass2ebs.txt"

If File.Exists(NewEbsFiles) = True Then
If File.Exists(OldEbsFiles) = True Then
File.Delete(OldEbsFiles)
End If
File.Copy(NewEbsFiles, OldEbsFiles)
End If
 
Use: system.IO.File.Move("source file as string","dest file as string")
 
thank for the reply.sorry for the confusion what I meant to say was I want to copy all files in one directory to another directory.
here I am mapping to the server to get the pass2ebs files and I would like to save this file in my local drive on c:\Expedite\pass2ebsfiles drive just in case i need this file in the future.

NewEbsFiles = "W:\IO\qebsfnam\pass2ebs"
OldEbsFiles = "C:\Expedite\gen\pass2ebs.txt"
 
Oh...then use this...

my.Computer.FileSystem.CopyDirectory("W:\IO\qebsfnam\pass2ebs","C:\Expedite\gen\pass2ebs.txt")

Be sure to post feedback on the reply. I post many replies and in my stats it states I have never replied to posts for some reason. Just venting...


 
thank you for the help. The file I have on this folder is always the same Pass2ebs and I donot want to overwirte this file and I am just wondering if I could add time and date like this pass2ebs.timedate? thanks again
 
Use system.IO.Directory.CreateDirectory to create the directory and append the date time to the directory name. Then do the copy into that directory.
 
thanks again for the reply. I want time and date to be append to the file instead of to the folder name. how can this be done?
 
Okay...try this...for the newname you can add whatever you want to the file...

Dim File, Files() As FileInfo
Dim oldname, newname As String
Dim Dir As New DirectoryInfo("W:\IO\qebsfnam")

Files = Dir.GetFiles("*.txt")

For Each File In Files
oldname = File.Name
newname = Trim(oldname) & Date.Today.Year.ToString
Console.Write(newname)
Console.WriteLine()
System.IO.File.Move("W:\IO\qebsfnam\" & oldname, "C:\Expedite\gen\" & newname)
Next

Console.ReadLine()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top