How can I move files from one location to another.

All

How can I move files from one location to another.

I currently have files that are produced every month and 'sent' to specific folders.  I would like to be able to then move these to another folder at the end of the month so that only the current month reports are available in the original folder

Example
Before new reports are 'sent' to the below folder

S:\Statement of Expectations\General Staff\Finance Office

I would like all files within the folder moved to

S:\Statement of Expectations\General Staff\Finance Office\old

Is this possible and if so can I do from a button or even on opening of the database.

TIA

shaz
shaz0503Asked:
Who is Participating?
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Connect With a Mentor Infotrakker SoftwareCommented:
You can use FileCopy to do this:

Dim sFiles as String

sFiles = Dir("Path to your folder\*.*")

Do Until sFiles = ""
  FileCopy "Source", "Destination"
  sFiles = Dir
Loop

Or you can use Name instead of FileCopy:

Name "Your Old File" As "Your New File"

0
 
shaz0503Author Commented:
Thanks

I have used your suggestion must be doing something wrong.

Below is what I am using - is this correct

Private Sub Command16_Click()
Dim sFiles As String

sFiles = Dir("S:\Statement of Expectations\General Staff\Finance Office\*.*")

Do Until sFiles = ""
  FileCopy "S:\Statement of Expectations\General Staff\Finance Office", "S:\Statement of Expectations\General Staff\Finance Office\Old"
  sFiles = Dir
Loop


End Sub

thx
S
0
 
Rey Obrero (Capricorn1)Commented:
you did not include the file

sFiles = Dir("S:\Statement of Expectations\General Staff\Finance Office\*.*")

Do while sFiles <> ""
  FileCopy "S:\Statement of Expectations\General Staff\Finance Office\" & sFiles, "S:\Statement of Expectations\General Staff\Finance Office\Old\" & sFiles
  sFiles = Dir
Loop

0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
shaz0503Author Commented:
Thanks

Works a treat but I neglected to mention in the first instance that I need to cut/remove these files and paste to new directory.

tia

s
0
 
Rey Obrero (Capricorn1)Commented:
sFiles = Dir("S:\Statement of Expectations\General Staff\Finance Office\*.*")

Do while sFiles <> ""
  FileCopy "S:\Statement of Expectations\General Staff\Finance Office\" & sFiles, "S:\Statement of Expectations\General Staff\Finance Office\Old\" & sFiles

  'check if the file was copied
 if dir("S:\Statement of Expectations\General Staff\Finance Office\Old\" & sFiles) <> "" then
      'delete the file from the original folder
         kill "S:\Statement of Expectations\General Staff\Finance Office\" & sFiles
 end if

  sFiles = Dir
Loop
0
 
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
here is another way to move the file

sFiles = Dir("S:\Statement of Expectations\General Staff\Finance Office\*.*")

Do while sFiles <> ""

        name  "S:\Statement of Expectations\General Staff\Finance Office\" & sFiles  as  "S:\Statement of Expectations\General Staff\Finance Office\Old\" & sFiles


  sFiles = Dir
Loop
0
 
shaz0503Author Commented:
Thanks both -
Have been on leave and neglected to answer sooner,,,

This turns out to be a bigger than is worth..

Will continue to do the old way....

rgds
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.