How can I rename files on the HD from Access VBA?

A

Alan B. Densky

I'm running Access 2000.

I download files for import on a dialy basis. I would like to automatically
rename the files from a function in my database before importing them.

The file names are always different, but they follow a pattern. There are
two files in the import directory before I run the import.

C:\ImportData\C32-0852361-1.txt
C:\ImportData\C32-0852361-2.txt

The first file always starts with the letter "C" and ends with "-1.txt"

C:\ImportData\C32-0852361-1.txt

I want to change the file extention to "csv" - C32-0852361-1.csv

The second file also starts with the letter "C" and it ends in "-2.txt"

C:\ImportData\C32-0852361-2.txt

I want to append the letter "L" to the beginning of the file name, and
change the file extention to "csv" - LC32-0852361-2.csv

Can someone please give me the code for this?

Thanks in advance.

Alan
 
J

Jeanette Cunningham

Alan
there is a Name statement in VBA to do this.

Name Statement Example from the vba help file.
This example uses the Name statement to rename/move a file.
For purposes of this example, assume that the directories or folders that
are specified already exist.

Dim OldName as String
Dim NewName as String

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

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


Jeanette Cunningham
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top