Results 1 to 11 of 11
  1. #1
    DittoBird's Avatar
    DittoBird is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2015
    Location
    Newfoundland & Labrador, Canada
    Posts
    59

    Find Windows Folder, Rename Files - Use API or Can VBA Handle This Now?

    Hi folks,

    I'm talking about manipulating the Windows directories/folders/files. Decades ago when I was working with A97 and later A2003, I had to use APIs (http://access.mvps.org/access/index.html was a great resource) to find files, created directories/folders, change file names, copy files, etc.

    At the moment, I am putting something together for my own purposes at work to be able to examine hundreds of files named in the convention test1.jpg, test2.jpg, ... test10.jpg, test11.jpg and add one or more leading 0s as necessary so that windows sort works properly. The result would be file names would change to test01.jpg, test02.jpg, ... test10.jpg, test11.jpg.



    Before I go hunting through my old code, I'm just wondering if VBA can handle all of this?

    Thanks in advance,
    --
    Tim

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716

  3. #3
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Create directory:
    Code:
    MkDir "C:\My_Directory"
    https://www.techonthenet.com/excel/formulas/mkdir.php



    Rename/move files:
    Code:
    Name "C:\test1.jpg" As "C:\test01.jpg"
    https://stackoverflow.com/questions/...with-excel-vba



    Copy file:
    Code:
    FileCopy "C:\test1.jpg", "C:\test01.jpg"
    https://www.rondebruin.nl/win/s3/win026.htm



    Delete file:
    Code:
    Kill "C:\test1.jpg"
    https://stackoverflow.com/questions/...-a-file-in-vba

  4. #4
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    In addition, I believe you'll find convenient the functionality of the members of the FileSystemObject.
    Review: https://docs.microsoft.com/en-us/off...mobject-object

  5. #5
    DittoBird's Avatar
    DittoBird is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2015
    Location
    Newfoundland & Labrador, Canada
    Posts
    59
    Quote Originally Posted by kd2017 View Post
    Create directory:
    Code:
    MkDir "C:\My_Directory"
    https://www.techonthenet.com/excel/formulas/mkdir.php



    Rename/move files:
    Code:
    Name "C:\test1.jpg" As "C:\test01.jpg"
    https://stackoverflow.com/questions/...with-excel-vba



    Copy file:
    Code:
    FileCopy "C:\test1.jpg", "C:\test01.jpg"
    https://www.rondebruin.nl/win/s3/win026.htm



    Delete file:
    Code:
    Kill "C:\test1.jpg"
    https://stackoverflow.com/questions/...-a-file-in-vba
    Thank you, kd, I appreciate this. I could not get Name to work on my installation of A2016, so I used Filecopy instead.

  6. #6
    DittoBird's Avatar
    DittoBird is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2015
    Location
    Newfoundland & Labrador, Canada
    Posts
    59
    Quote Originally Posted by orange View Post
    All in same directory/folder?
    Hi Orange. No, I'd put each renamed file into a new directory.

    I came up with a solution, but the code for what I wanted to do is quite long with a lot of warnings to the user i.e. -->ME<-- I did use the old Windows API for browsing for a folder name and path from http://www.theaccessweb.com/api/api0002.htm

    I'm not sure if you think it's useful, but I can post the code if you think I should. I have been getting screen shots of the maintenance management system I administered for 18 or so years from former colleagues, and the .pngs are numbered from 1 to 30, for example. I just wanted to change that to 01 to 30 and figured it would be nice to have and save a utility to do so. It would have been easier to go through and rename each file "handraulically" (by hand), but after 4 or 5 hours, I can now do this quickly for other instances. It was a good review for me.
    --
    Tim

  7. #7
    DittoBird's Avatar
    DittoBird is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2015
    Location
    Newfoundland & Labrador, Canada
    Posts
    59
    Quote Originally Posted by accesstos View Post
    In addition, I believe you'll find convenient the functionality of the members of the FileSystemObject.
    Review: https://docs.microsoft.com/en-us/off...mobject-object
    Thank you, this looks interesting. I've already completed what I want, but I've bookmarked this for exploration later. Much appreciatied.
    --
    Tim

  8. #8
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Hi Tim,

    I see you have a solution from John (accesstos). Good stuff.

    I found some code from FMS.

    I have attached my adjusted code/usage. It will rename a file and move it from one directory to another.
    May not be of use to you now.
    Attached Files Attached Files

  9. #9
    DittoBird's Avatar
    DittoBird is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2015
    Location
    Newfoundland & Labrador, Canada
    Posts
    59
    Quote Originally Posted by orange View Post
    Hi Tim,

    I see you have a solution from John (accesstos). Good stuff.

    I found some code from FMS.

    I have attached my adjusted code/usage. It will rename a file and move it from one directory to another.
    May not be of use to you now.

    Thank you for your time on this, Orange person. I've saved this as I may well be revisiting the subject in the future.
    --
    Tim

  10. #10
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Quote Originally Posted by orange View Post
    Hi Tim,

    I see you have a solution from John (accesstos). Good stuff.

    I found some code from FMS.

    I have attached my adjusted code/usage. It will rename a file and move it from one directory to another.
    May not be of use to you now.
    Oh sure, snub the guy that answered the question! Lol "I don't get no respect!" -RD

  11. #11
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    10-4. Good luck with your project.
    My testing shows the code will move/rename a file from one directory to another, including sub directories, but the directories must exist. It doesn't create a new directory/sub directory. The original material says it will not move files across drives.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 10
    Last Post: 09-09-2015, 03:25 AM
  2. Replies: 1
    Last Post: 05-15-2015, 10:58 AM
  3. Replies: 2
    Last Post: 08-27-2013, 06:29 AM
  4. Replies: 21
    Last Post: 08-20-2012, 11:59 PM
  5. Copying and Rename of Files based on fields
    By desk4tbc in forum Programming
    Replies: 2
    Last Post: 06-28-2011, 11:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums