+ Reply to Thread
Results 1 to 7 of 7

Loop through a set of files and check if a file doesn't exist

  1. #1
    Registered User
    Join Date
    12-18-2013
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    24

    Loop through a set of files and check if a file doesn't exist

    Hello everyone,

    I am struggling with this the last days so I would appreciate if you could help me. My problem is that I want to loop through a directory that contains csv files. The directory is dynamic so everytime could be a different number of files inside. I want the loop to go through each file and check if that file exists. If it doesn't to print a message that this specific files doesn't exist. Until now I got the following code:
    Please Login or Register  to view this content.
    I guess I should somehow place the counter j inside the Dir path in order to check if everytime time the file[j] exists?

    Thank you in advance

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Loop through a set of files and check if a file doesn't exist

    Try changing & "\*.csv" to & "\" & j ".csv"

  3. #3
    Registered User
    Join Date
    12-18-2013
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Loop through a set of files and check if a file doesn't exist

    Thanks for the reply i did this :
    Please Login or Register  to view this content.
    but there is a compile error->Expected list separator or ) at the ".csv" part

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Loop through a set of files and check if a file doesn't exist

    I don't get it. why loop twice when the first Dir only returns files that do exist?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Registered User
    Join Date
    12-18-2013
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Loop through a set of files and check if a file doesn't exist

    Because how can I check the missing file ? I mean, if for example i got 10 files and the 05.csv is missing , don't I have to loop first to see how many i got in total and then find the missing one? I don't know, I agree the code is bad but i am trying it to do it step by step.

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Loop through a set of files and check if a file doesn't exist

    but the number of files returned by the first loop won't tell you much-you've gotta know the biggest file number. if you've got three files 1,2 and 10 your second loop would only go from 1 to 3 otherwise. you could store the file names on the first pass too - something like this:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-18-2013
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Loop through a set of files and check if a file doesn't exist

    Thank you very much for the explanation. I think I got it know. Thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 11-19-2013, 04:11 PM
  2. VBA Loop for a folder of all the files, Loop all the worksheet in each workbook
    By nanjingwoodworking in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-07-2013, 07:20 PM
  3. Replies: 0
    Last Post: 03-13-2013, 09:08 PM
  4. Replies: 0
    Last Post: 07-20-2010, 11:42 AM
  5. VBA Loop, And Check Function
    By lilanngel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-23-2010, 03:00 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1