Renaming and moving files

  • Thread starter Thread starter bill
  • Start date Start date
B

bill

Can anyone help!

I am designing an image database. At present the images as stored in a image
directory. I want to move each image from image directory to another
directory and rename each image file. Storing the location and name in a
table.
Is there a way of doing this using VB.
Thanks for you time!!
 
I use the FileSystemObject for this type of stuff

Dim fso as New FileSystemObject
fso.MoveFile("Source", "Destination")
set fso = nothing

You can use this in a recordset Do...Loop based on your
control table to move files.

Destination will rename the file for you.

HTH

Mike.
 
No need to introduce the bulk of FSO into your application.

VBA has built-in functions to do copies and renames.

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

Both newpathname and oldpathname must be on the same drive. If the path in
newpathname exists and is different from the path in oldpathname, the Name
statement moves the file to the new directory or folder and renames the
file, if necessary. If newpathname and oldpathname have different paths and
the same file name, Name moves the file to the new location and leaves the
file name unchanged. Using Name, you can move a file from one directory or
folder to another, but you can't move a directory or folder.


FileCopy source, destination

The FileCopy statement syntax has these named arguments:

Part Description
source Required. String expression that specifies the name of the file to be
copied. The source may include directory or folder, and drive.
destination Required. String expression that specifies the target file name.
The destination may include directory or folder, and drive.
Remarks

If you try to use the FileCopy statement on a currently open file, an error
occurs.

And just in case you need to delete files:

Kill pathname

The required pathname argument is a string expression that specifies one or
more file names to be deleted. The pathname may include the directory or
folder, and the drive.

Remarks

Kill supports the use of multiple-character (*) and single-character (?)
wildcards to specify multiple files.

An error occurs if you try to use Kill to delete an open file.
 
Back
Top