اذهب الي المحتوي
أوفيسنا
بحث مخصص من جوجل فى أوفيسنا
Custom Search

دالة في اكسس تقوم بفحص مجلد وتخبرني اذا كان يوجد به ملفات أم هو فارغ


الردود الموصى بها

تفضل هذا الكود فقط تحتاج الى اختيار مسار المجلد الذي تريد التاكد من وجود ملفات بداخله 

 

Dim FileName As String

    FileName = VBA.FileSystem.Dir("C:\Users\No one\Desktop\test\*.*")

    If FileName = VBA.Constants.vbNullString Then
        MsgBox "الملف فاضي"
    Else
        MsgBox "يوجد ملفات داخل المجلد"
    End If

 

هذا يعتبر مسار المجلد

C:\Users\No one\Desktop\test\

هنا سوف يجلب لك اي اسم لاي فايل واي امتداد داخل المجلد في حال انك اردت ان تتاكد من نوع معين من الملفات او ملف بعينه يمكن وضع اسم ومتداد الملف او امتداد الملف فقط او اسم الملف فقط

*.*

 

  • Thanks 1
رابط هذا التعليق
شارك

وعليكم السلام ورحمة الله وبركاته 🙂 

مشاركة مع أخي أحمد ..

وجدت هذا الكود ووظيفته حساب عدد الملفات ( وليس المجلدات ) في مجلد  معين ويعطيك عددها  :

Public Function CountFilesInFolder(strDir As String, Optional strType As String)
'DEVELOPER: Ryan Wells (wellsr.com)
'DESCRIPTION: This macro counts the files in a folder and retuns the result in a msgbox
'INPUT: Pass the procedure a string with your directory path and an optional
' file extension with the * wildcard
'EXAMPLES: Call CountFilesInFolder("C:\Users\Ryan\")
' Call CountFilesInFolder("C:\Users\Ryan\", "*txt")
    Dim file As Variant, i As Integer
    If Right(strDir, 1) <> "\" Then strDir = strDir & "\"
    file = Dir(strDir & strType)
    While (file <> "")
        i = i + 1
        file = Dir
    Wend
    MsgBox i
End Function

وتستخدمه هكذا :

Call CountFilesInFolder("C:\Users\Ryan\Documents\")

ويمكنك من حساب عدد ملفات من نوع معين ( ملفات الأكسل مثلا ) هكذا :

Call CountFilesInFolder("C:\Users\Ryan\Documents\", "*.xls*")

 

https://wellsr.com/vba/2016/excel/vba-count-files-in-folder/

 

 

 

 

  • Like 2
رابط هذا التعليق
شارك

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

زائر
اضف رد علي هذا الموضوع....

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • تصفح هذا الموضوع مؤخراً   0 اعضاء متواجدين الان

    • لايوجد اعضاء مسجلون يتصفحون هذه الصفحه
×
×
  • اضف...

Important Information