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

Copy/Rename/Delete Files from within Access using VBA

Status
Not open for further replies.

brettatexplace

Technical User
Mar 8, 2002
60
CA
Need a little help remembering. I need to copy, rename and delete files in a folder on the network, from within Access using VBA linked to a button. I can't get the shell command to work! Can someone please provide a example of the syntax. Thanks in advance.
 
Name OldName As NewName ' Move and rename file.

FileCopy source, destination

Kill "TestFile" ' Delete file.

F1 will give you more info on these.

ChaZ



There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.
 
I have a list of files, which include dates as part of their filenames, contained in C:\Files . An example of the filename format is shown below, with 102905 representing the date portion of the filename. Is there any way to loop through the files of C:\Files, and copy only those containing the current date listed to another folder while ignoring others? Thanks for your help


ixml_database_1029050942.xml.051029-094346
 
Have a look at the Dir and Format functions:
ChDir "C:\Files"
f = Dir(Format(Date, "\*_mmddyy\*"))
While f <> ""
MsgBox f
f = Dir()
WEnd

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi iojbr,

You could try using FileSystemObject:

Code:
Dim fs As FileSystemObject
Dim fl As File
Dim fld As Folder

Dim strFileNameShort As String

Set fs = New FileSystemObject

'Set the path to the files 
Set fld = fs.GetFolder("C:\Files")

'Loop through all of the files in the folder
For Each fl In fld.Files

'Set the variable to reference the current file
strFileNameShort = fl.Name

'Test the date
If Mid(strFileNameShort, InStr(InStr(1, strFileNameShort, ".")+1, strFileNameShort, ".")+1, 6) = format(int(now()),"ddmmyy") Then

'It matches, copy the file
fl.Copy("NewFileLocationHere")

Else 'do nothing

End If

Next fl

This relies on you having the 'string.xml.date-string' format for all of your filenames. I note also that you've given two seperate formats for the date in your post, so you may need to change the format function above.

Hope that helps, Iain

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top