Results 1 to 5 of 5
  1. #1
    SodaPop is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2014
    Posts
    16

    Proper Way to Look Up and Manipulate files

    I am trying to build a DB to fix movie folders and file names and I am struggling to properly find the file names.

    Currently I am using "DirectoryName = Dir(folder, vbDirectory)" to find the files and loop through them correcting the names as I go.

    Works perfect.

    The issue I am having is how to properly then look up the file within the folder since Dir is already in use for the loop.



    The straightforward question is how does one look-up a child file when the parent is known without using Dir().

    Below is what is works to rename parent folders. I am sure it is hack to the trained eye but it gets the job done.

    folder = "E:\Videos\"
    DirectoryName = Dir(folder, vbDirectory)

    Do Until DirectoryName = ""
    If DirectoryName <> "." And DirectoryName <> ".." Then
    If (GetAttr(folder & DirectoryName) And vbDirectory) = vbDirectory Then

    FrstNum = ""
    FixIt = Replace(DirectoryName, "'", "")
    FixIt = Replace(FixIt, ".", " ")
    ChrCnt = Len(FixIt)

    For i = 5 To ChrCnt
    If IsNumeric(Mid(FixIt, i, 1)) = True Then FrstNum = i
    If FrstNum <> "" Then i = ChrCnt
    Next i

    If FrstNum = "" Then Yr = "(0000)" Else Yr = "(" & Mid(FixIt, FrstNum, 4) & ")"
    If FrstNum = "" Then ChrCnt = ChrCnt Else If Mid(FixIt, FrstNum - 1, 1) = "(" Then ChrCnt = FrstNum - 3 Else ChrCnt = FrstNum - 2

    Fname = Left(FixIt, ChrCnt)
    Rname = Fname & " " & Yr
    OldName = folder & DirectoryName
    NewName = folder & Rname

    Name OldName As NewName


    End If
    End If
    DirectoryName = Dir

    Loop

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Will this help http://www.allenbrowne.com/ser-59.html

    Don't understand the issue with using Dir() more than once. It's a function, not a variable.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    SodaPop is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2014
    Posts
    16
    Unfortunately no, I referenced that one too already. That and most other code I've found explicitly references building a list of files.

    I am looping through a set of folders. Each folder has a movie file in it. In order for the loop to work properly access needs to maintain the Dir() reference to know which file it was last on otherwise it starts over. Essentially using Dir() the second time kills the loop. I've played around with trying to maintain the reference but it either starts over or exits the function due to a null (which is coded in).

    Starting to think it will be easier to build a reference table. Put in the old and new file names then loop through those in the rename.

    Longer but I know for sure that can be done. Was just hoping there was another lookup method beyond Dir(). Anyway, likely will mess around some with the link and see if I can manipulate it...

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    How many folder levels do you need to loop through? Just one?

    I use FileSystemObject collection to declare and set folder objects to manipulate files.
    This is part of a long procedure that saves reports as PDF then combines them with existing PDF documents.

    Dim fso As Object, SourceFolder As Object, SFolder As Object, SSFolder As Object, SSSFolder As Object, PDFile As Object
    Set objCAcroPDDocDestination = CreateObject("AcroExch.PDDoc")
    Set objCAcroPDDocSource = CreateObject("AcroExch.PDDoc")
    Set SourceFolder = fso.GetFolder("R:\Projects\LabReportsTemp\")For Each SFolder In SourceFolder.subfolders
    strPath = SourceFolder.Path & "\" & SFolder.Name
    If Dir(strPath, vbDirectory) = "" Then MkDir strPath
    For Each SSFolder In SFolder.subfolders
    ...
    For Each PDFile In SSSFolder.Files
    ...
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    SodaPop is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2014
    Posts
    16
    Quote Originally Posted by June7 View Post
    How many folder levels do you need to loop through? Just one?

    I use FileSystemObject collection to declare and set folder objects to manipulate files.
    This is part of a long procedure that saves reports as PDF then combines them with existing PDF documents.

    Dim fso As Object, SourceFolder As Object, SFolder As Object, SSFolder As Object, SSSFolder As Object, PDFile As Object
    Set objCAcroPDDocDestination = CreateObject("AcroExch.PDDoc")
    Set objCAcroPDDocSource = CreateObject("AcroExch.PDDoc")
    Set SourceFolder = fso.GetFolder("R:\Projects\LabReportsTemp")For Each SFolder In SourceFolder.subfolders
    strPath = SourceFolder.Path & "" & SFolder.Name
    If Dir(strPath, vbDirectory) = "" Then MkDir strPath
    For Each SSFolder In SFolder.subfolders
    ...
    For Each PDFile In SSSFolder.Files
    ...
    Wow what difference 3 years makes. I could do this blindfolded now. Lol.

    Sent from my SM-G950U using Tapatalk

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

Similar Threads

  1. Tags property manipulate group of fields
    By Ruegen in forum Forms
    Replies: 9
    Last Post: 03-20-2014, 05:39 PM
  2. manipulate file before import
    By tagteam in forum Programming
    Replies: 3
    Last Post: 06-14-2013, 12:45 PM
  3. Using VBA to manipulate properties in a Report
    By adacpt in forum Programming
    Replies: 1
    Last Post: 11-26-2012, 09:22 PM
  4. 2-questions regarding data manipulate date:
    By djclntn in forum Queries
    Replies: 6
    Last Post: 08-12-2012, 12:29 PM
  5. Manipulate DB through VB ...
    By Zoroxeus in forum Programming
    Replies: 2
    Last Post: 12-18-2005, 01:16 PM

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