Query files-VBForums
Results 1 to 8 of 8

Thread: Query files

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2010
    Posts
    43

    Query files

    Hi!

    I have a problem with file query.

    I have a folder. and there are many folders under this folder. like this;

    01022017
    02022017
    03022017
    ...
    25022017

    and there are hundreds of files in each folders.

    for example 01022017 folder's files

    c:\01022017\01022017_140245.txt
    c:\01022017\01022017_230111.txt

    (foldername_time.txt)

    I want to query between two date and two time.

    sample: first date: 01.02.2017 time:13:25= > and <=second date 05.02.2017 time :08:00

    and write file names to listbox.


    can you help me.

    sorry for my English

    Thanks

  2. #2
    Frenzied Member
    Join Date
    Dec 2008
    Posts
    1,062

    Re: Query files

    Do you have control over the naming of the folders and the files ?
    If you do, I would sleep easier at night if you used this format instead - YYYYMMDD
    a) They look nicer in your file manager, because they sort the way God intended
    b) Your program will work in strange countries like the US where they show their dates wrong MMDDYYYY

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,354

    Re: Query files

    Is this
    01022017_140245.txt
    a date_time, that is the date (MMDDYYY or DDMMYYYY????) and some sort of 'time' (14th hr, 02nd minute. 45th second?)?

  4. #4
    PowerPoster
    Join Date
    Oct 2013
    Posts
    2,911

    Re: Query files

    Just collect all filenames using the Dir() function
    While retrieving a filename check whether the filename matches the specifications.
    Using the Mid() method you can get the date and the time from the filename.
    If these date and time matches your criteria add them to your list.

    It's easy to write to code for, but first try something yourself.
    If you still have problems show us the code you have used and tell what's is going wrong.

  5. #5
    Lively Member
    Join Date
    Feb 2017
    Posts
    101

    Re: Query files

    what happens when more than 1 file is written in the same second to the same folder ?

  6. #6
    Hyperactive Member
    Join Date
    Oct 2016
    Posts
    369

    Re: Query files

    Quote Originally Posted by SamOscarBrown View Post
    Is this a date_time, that is the date (MMDDYYY or DDMMYYYY????) and some sort of 'time' (14th hr, 02nd minute. 45th second?)?
    That would have been my guess but OP stated the time was 13:25 and I could not find anything that 13:25 could be converted to 140245. I tried minutes, and seconds but they don' compute

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,018

    Re: Query files

    That would have been my guess but OP stated the time was 13:25 and I could not find anything that 13:25 could be converted to 140245
    he did not say that that 13:25 was the time of that file, he specified files between the two times over several days

    as it would appear that each days files are in a separate folder, he would need to parse multiple folders, based on the query dates, and should only need to look at the time criteria of files in the first and last folder
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8
    Hyperactive Member
    Join Date
    Oct 2016
    Posts
    369

    Re: Query files

    Oh so it is

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.