How to rename a file

smiler44

Registered User.
Local time
Today, 22:43
Joined
Jul 15, 2008
Messages
678
I'm using version 5 and want to rename some files. a search on the internet gave me this
Code:
my.Computer.FileSystem.RenameFile([COLOR=maroon]"C:\Test.txt"[/COLOR], [COLOR=maroon]"SecondTest.txt"[/COLOR])

I have put the code to a command button but as soon as I move the cursor away I get an error message saying "compile error expected ="

sorry but yet again I have crashed and burnt and find myself asking for help.

any advice please?
smiler44
 
I see the NAME is available in ver 6.5. Maybe ok for ver 5. Here's the help:



Name Statement

Renames a disk file, directory, or folder.

Syntax

Name oldpathname As newpathname

The Name statement syntax has these parts:

Part Description
oldpathname Required. String expression that specifies the existing file name and location — may include directory or folder, and drive.
newpathname Required. String expression that specifies the new file name and location — may include directory or folder, and drive. The file name specified by newpathname can't already exist.

Remarks

The Name statement renames a file and moves it to a different directory or folder, if necessary. Name can move a file across drives, but it can only rename an existing directory or folder when both newpathname and oldpathname are located on the same drive. Name cannot create a new file, directory, or folder.

Using Name on an open file produces an error. You must close an open file before renaming it. Name arguments cannot include multiple-character (*) and single-character (?) wildcards.

Example
This example uses the Name statement to rename a file. For purposes of this example, assume that the directories or folders that are specified already exist. On the Macintosh, "HD:" is the default drive name and portions of the pathname are separated by colons instead of backslashes.

Dim OldName, NewName
OldName = "OLDFILE": NewName = "NEWFILE" ' Define file names.
Name OldName As NewName ' Rename file.

OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE"
Name OldName As NewName ' Move and rename file.


hth
Chris
 
Chris,
thank you. I must be very tired, did not read your post properly and must have taken a dozen attempts to get it right. Ho hum.

Thank you vey much

smiler44
 

Users who are viewing this thread

Back
Top Bottom