Consulting

Results 1 to 2 of 2

Thread: Backup files from one folder to other date separated folders

  1. #1

    Smile Backup files from one folder to other date separated folders

    Hi guys. I'm totally new to VBA, and this forum.
    I need help with a script.
    I have a folder with txt and xml files, and I need to move files from that folder to backup folder.
    The script should run twice a week and should create (in the destination folder) subfolder with date in format like 2018.12 (year and month), and move files there. If there is already a subfolder with current month's date, than it should just move files there.
    Any help will be appreciated. Thank you.

  2. #2
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    344
    Location
    Hi AlexPerry!
    Something like below:
    Sub test()
    Dim sourcePath$, fileName$, targetPath$
    sourcePath = "C:\abc\sourcefolder\"
    targetPath = "C:\abc\backup\" & Format(Date, "yyyy.mm") & "\"
    If Dir(targetPath) = "" Then MkDir targetPath
    ChDir (sourcePath)
    fileName = Dir("*.xls")
    Name sourcePath & fileName As targetPath & fileName
    Do
      fileName = Dir
      If fileName = "" Then Exit Do
      Name sourcePath & fileName As targetPath & fileName
    Loop
    End Sub

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •