Re: Using VB to rename and move files ?
- From: "Ron" <roduku@xxxxxxxxxxx>
- Date: 2 Jul 2005 12:43:43 -0700
Hi, Steven.B
Here are a few things I got from my copy of MSDN. You can use the
online reference at: http://msdn.microsoft.com/library/default.asp
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. Namearguments cannot include
multiple-character (*) and single-character (?) wildcards.
Name Statement 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.
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.
SubFolders Property
Description
Returns a Folders collection consisting of all folders contained in a
specified folder, including those with Hidden and System file
attributes set.
Syntax
object.SubFolders
The object is always a Folder object.
Remarks
The following code illustrates the use of the SubFolders property:
Sub ShowFolderList(folderspec)
Dim fs, f, f1, s, sf
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set sf = f.SubFolders
For Each f1 in sf
s = s & f1.name
s = s & vbCrLf
Next
MsgBox s
End Sub
Kill Statement
Deletes files from a disk.
Syntax
Kill pathname
The required pathnameargument is astring expression that specifies one
or more file names to be deleted. The pathname may include the
directory or folder, and the drive.
Remarks
In Microsoft Windows, Kill supports the use of multiple-character (*)
and single-character (?) wildcards to specify multiple files
Kill Statement Example
This example uses the Kill statement to delete a file from a disk.
' Assume TESTFILE is a file containing some data.
Kill "TestFile" ' Delete file.
' Delete all *.TXT files in current directory.
Kill "*.TXT"
I hope this is helpful...if you have anything else, post it here and
I'll see what I can do.
.
- Follow-Ups:
- Re: Using VB to rename and move files ?
- From: Stephen.B
- Re: Using VB to rename and move files ?
- References:
- Using VB to rename and move files ?
- From: Stephen.B
- Using VB to rename and move files ?
- Prev by Date: Re: Finding Largest of 4 Variables
- Next by Date: Re: Inet1.OpenURL
- Previous by thread: Using VB to rename and move files ?
- Next by thread: Re: Using VB to rename and move files ?
- Index(es):
Relevant Pages
|