Results 1 to 14 of 14
  1. #1
    kallm is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    10

    Dir function vbdirectory returns a single dot

    Hi, everybody
    I' m looking over the net for the answer to this question with no luck.


    When running the
    Code:
     Dir ("somePath" & "\" ,vbdirectory)
    function, it returns a single dot "." what does this mean?

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    From my old DOS days, a single dot refers to the current directory you are in when the command is issued.

  3. #3
    kallm is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    10
    Anybody there ?

  4. #4
    kallm is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    10
    Ok thanks for the answer but i' m getting confused, it supposed to return the existing folder name, otherwise null string. Is this a bug or something?

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    try moving the close parens
    Dir ("somepath" & "/"), vbdirectory

  6. #6
    kallm is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    10
    it's not working, it gives me " 16" (spaces and 16 for the vbdirectory)

  7. #7
    kallm is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    10
    I run this sub and indeed it returns among the other files and folders "." and ".." in my directory. I' ve also mooved my files to a new directory but still the dots are there, ihave no clue whats going on
    Code:
    Sub smthing()
    Dim fList As String
    Dim fName As String
    fName = Dir(currentproject.path & "\Data\Backup\", vbDirectory)
    
    Do While fName <> ""
    ' Store the current file or directory name in the string fList.
    fList = fList & vbNewLine & fName
    ' Get the next file or directory within "C:\".
    fName = Dir()
    ' The variable fName now contains the name of the next file or directory within "C:\".
    Loop
    ' Display the list of directories in a message box.
    MsgBox ("File List:" & fList)
    
    End Sub

  8. #8
    kallm is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    10
    the only workaround i can think is to put something like that:
    Code:
    Do while Left(str,1) = "."
    str = Dir()
    Loop
    ...but it is still mystery to me

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The single dot (.) is the current directory.
    The double dot (..) is the parent directory.

    To test this......
    1) Open a command window.
    2) Enter the command DIR (you should see a list)
    3) Then type CD, a space, then a directory name from the DIR list. (This will change to the sub directory.)
    4) Now type DIR ..
    You will see the same listing as the first DIR command - the parent directory listing.
    5) Type "CD .." (no quotes) This will move you up one level (to the parent directory) in the directory structure.

  10. #10
    kallm is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    10
    ...mmm interesting, but what is the purpose of getting involved with dir function at vba? this can make you crazy as it can ruin your logic of code, am i missing smthing?

  11. #11
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Well.....

    Lets say you have a folder with 30 CSV files and 35 Excel files and you need to import only the CSV files.
    You might use code similar to the following AIR code:
    Code:
    tmpFile = Dir("C:\AcctFiles\2016\*.csv")
    
    
    Do While tmpFile <> ""
    
       Import code for the csv file goes here
    
       ' get next csv file name
       tmpFile = Dir
    
    Loop
    Beats having to pick them one at a time......

  12. #12
    kallm is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    10
    I don't get it, I would use the code that you mentioned, for same purpose, but what this has to do with the "." and ".." . Why the above code wouldn't work having in mind that theese two "files" do not exist?
    Anyway, it is very strange that is not mentioned anywhere in the explanation of dir func. Thanks for your help.

  13. #13
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Last thoughts, I promise

    Why the above code wouldn't work having in mind that these two "files" do not exist?
    "." and ".." are not files any more that the "Start Up" folder (aka directory) is a file.
    Think of them as pointers - they are how DOS keeps track of a directory in the linked list of directories.

  14. #14
    apr pillai's Avatar
    apr pillai is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2010
    Location
    Alappuzha, India
    Posts
    209
    Check the examples below to get some idea about Dir() command in VBA. These commands can be directly executed on the Debug Window.

    Sample folder structure and files:

    Code:
    C:\FirstFolder\InnerFolder\201605.pdf
                               \201607.pdf
                               \ACCESS2.txt
     C:\FirstFolder\Survey.pdf
    Sample Commands and their result:

    Code:
    ? dir("c:\FirstFolder\InnerFolder",vbNormal) - Returns Empty String
    
                       Above command checks whether InnerFolder is a file inside the path c:\FirstFolder\ or not. InnerFolder is not a file, hence returns an empty string.
     
     ? dir("c:\FirstFolder\InnerFolder",vbDirectory) - Returns InnerFolder
    
                       InnerFolder inside the path c:\FirstFolder\ is a Folder and returns it's Name.
     
     ? dir("c:\FirstFolder\InnerFolder\",vbNormal) - Returns 201605.pdf
    
                        Looks for Files inside specified path and returns the first file name.
    
    Note: After executing the above command, run ? Dir() command without parameters to return the next file name.  This can be repeated until all files are accessed this way. After that it will run into Error, if executed without necessary parameters.
    
     ? dir("c:\FirstFolder\InnerFolder\",vbDirectory) - Returns . (dot) stating that ..\InnerFolder\ is a Folder. 
    
                        Unlike the previous command it will not return the first file name.
     
     
     ? dir("c:\FirstFolder\InnerFolder\..",vbNormal) - Returns the file name: Survey.pdf
    
                        usage of \.. gets the first filename (if files exists), one level up from \InnerFolder folder.
     
     ? dir("c:\FirstFolder\InnerFolder\..",vbDirectory) - Returns . (dot)
    
                        One level up is a folder above the folder \InnerFolder.
     
     ? dir("c:\FirstFolder\InnerFolder\..\..",vbNormal) - Returns an empty string, if no files in c:\ (Root Directory) otherwise it returns the first file name.
     
     ? dir("c:\FirstFolder\InnerFolder\..\..",vbDirectory) - Returns the first folder name from C:\ directory.
    
                         Subsequent dir() command without any parameters will get the next folder name from C:\.
    Last edited by apr pillai; 07-27-2016 at 04:42 AM. Reason: highlighting the command parameter

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

Similar Threads

  1. Function that returns an array
    By lefty2cox in forum Programming
    Replies: 6
    Last Post: 03-03-2016, 04:34 PM
  2. User Defined Function Returns Ambiguous Name Error
    By HotsauceHero in forum Modules
    Replies: 8
    Last Post: 10-03-2014, 04:09 PM
  3. Replies: 1
    Last Post: 08-21-2014, 02:15 PM
  4. Val function returns #error on text/percentage
    By allenjasonbrown@gmail.com in forum Queries
    Replies: 1
    Last Post: 06-23-2013, 08:24 AM
  5. Aggregate function returns duplicate values
    By lokiluke in forum Queries
    Replies: 3
    Last Post: 09-16-2011, 09:40 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