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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Copy program

Status
Not open for further replies.

arrian

Programmer
Nov 11, 2003
93
CA
I'm writing a program to copy a file to a static location, with a static name. I've got this working, but the problem is, I need to rename the original file. I need to add a z to the start of the file name of the original. How could I do this? Also, how can I get the open dialog box to not display any files starting with a z? Here's the code I have so far:

Code:
Dim strFile As String

        ofdOpen.Filter = "Text File|*.txt"

        If ofdOpen.ShowDialog = Windows.Forms.DialogResult.OK Then
            strFile = ofdOpen.FileName
        Else
            End
        End If

        FileCopy("C:\B7\PY7334\f0611621.txt", strFile)
 
Take a look at: System.IO.FileInfo namespace and specifically the .MoveTo() property. If you use this then:
- will move the file if the destination directory is different
- will rename it if the source and destination dirs are the same. (put filename "z" & strFilename.split(".")(0) for example)

Also two suggestions:
1. Why don't you use the .net functions instead of the FileCopy of vb6?
2. The "End" is not the best command. You can use the Exit Sub or just reform the If/Else statement.
 
this would be a shorter version

Code:
ofdOpen.Filter = "Text File|*.txt"
If ofdOpen.ShowDialog = Windows.Forms.DialogResult.OK Then
     system.IO.File.Move(ofdOpen.FileName,system.IO.Path.GetFullPath(ofdOpen.filename) & "\z" & system.IO.Path.GetFileName(ofdOpen.FileName)
        End If

sorry untested but pretty close.

no idea how to filter for not z

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
You could turn on the 'hidden' attribute for the files you don't want to display.

It would be slightly risky (in that files could get left as hidden if an error occurs) but you could loop through all of the files in the folder before opening the dialogue, and hiding anything that starts with 'z' then after the user has made their selection go back through and unhide everything.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top