الاخوة لدي مشكلة حيرتني وهي كيف احول المسار من مثلاً c:\atiyh\a1.doc إلى c:\atiyh علماً بان المسار متغير ولكم مني جزيل الشكر
مشكلة في تفقيط مسار البرنامج
السلام عليكم...
أرجو التوضيح: هل تقصد الحصول على مسار المجلد الذي يوجد به الملف؟
و السلام.
وَ قُلِ اعْمَلُوا فَسَيَرَى اللهُ عَمَلَكُمْ وَ رَسُولُهُ وَ الْمُؤْمِنُونَ
صدق الله العظيم
نعم اريد الحصول على مسار المجلد الذي يوجد به الملف
السلام عليكم...
هذه مجموعة دوال كنت كتبتها من مدة لمعالجة الوصول إلى الملفات. انسخها و ضعها في وحدة برمجية (Module) و استخدم ما بلزمك منها:
- ' الحصول على اسم الملف (و امتداده إذا كان موجوداً) من مسار محدد
- Public Function ExtractFileName(ByVal APath As String) As String
- Dim Index As Long
- Dim LastSlashPos As Long
- Dim AChar As String
- Dim ThePath As String
- ThePath = Trim(APath)
- If ThePath = "" Then
- ExtractFileName = ""
- Else
- LastSlashPos = InStrRev(ThePath, "")
- If LastSlashPos = 0 Then
- ExtractFileName = ThePath
- Else
- ExtractFileName = Mid(ThePath, LastSlashPos + 1)
- End If
- End If
- End Function
- ' الحصول على مسار المجلد المحتوي على الملف أو المجلد - أي الحصول على مسار المجلد الأب
- Public Function ExtractFilePath(ByVal APath As String) As String
- Dim Index As Long
- Dim LastSlashPos As Long
- Dim AChar As String
- Dim ThePath As String
- ThePath = Trim(APath)
- If ThePath = "" Then
- ExtractFilePath = ""
- Else
- LastSlashPos = InStrRev(ThePath, "")
- If LastSlashPos = 0 Then
- ExtractFilePath = ""
- Else
- ExtractFilePath = Left(ThePath, LastSlashPos)
- End If
- End If
- End Function
- ' الحصول على امتداد الملف
- Public Function ExtractFileExt(ByVal APath As String) As String
- Dim Index As Long
- Dim LastDotPos As Long
- Dim AChar As String
- Dim ThePath As String
- ThePath = Trim(APath)
- If ThePath = "" Then
- ExtractFileExt = ""
- Else
- LastDotPos = InStrRev(ThePath, ".")
- If LastDotPos = 0 Then
- ExtractFileExt = ""
- Else
- ExtractFileExt = Mid(ThePath, LastDotPos + 1, Len(ThePath))
- End If
- End If
- End Function
- ' استبدال امتداد الملف بامتداد آخر أو حذف الامتداد
- Public Function ReplaceFileExt(ByVal APath As String, ByVal NewExt As String) As String
- Dim Index As Long
- Dim LastDotPos As Long
- Dim AChar As String
- Dim ThePath As String
- ThePath = Trim(APath)
- If ThePath = "" Then
- ReplaceFileExt = ""
- Else
- LastDotPos = InStrRev(ThePath, ".")
- If LastDotPos = 0 Then
- If NewExt = "" Then
- ReplaceFileExt = ThePath
- Else
- ReplaceFileExt = ThePath & "." & NewExt
- End If
- ElseIf NewExt = "" Then
- ReplaceFileExt = Left(ThePath, LastDotPos - 1)
- Else
- ReplaceFileExt = Left(ThePath, LastDotPos) & NewExt
- End If
- End If
- End Function
- ' الحصول على الاسم الأساسي للملف - من غير امتداد
- Public Function ExtractFileBaseName(ByVal APath As String) As String
- Dim Index As Long
- Dim LastSlashPos As Long
- Dim AChar As String
- Dim ThePath As String
- Dim FName As String
- ThePath = Trim(APath)
- If ThePath = "" Then
- ExtractFileBaseName = ""
- Else
- ThePath = ExtractFileName(ThePath)
- ExtractFileBaseName = ReplaceFileExt(ThePath, "")
- End If
- End Function
- ' التأكد من وجود ملف
- Public Function FileExists(ByVal APath As String) As Boolean
- Dim Result As String
- Result = Dir(APath, vbNormal Or vbArchive Or vbReadOnly Or vbHidden Or vbSystem)
- If Result = "" Then
- FileExists = False
- Else
- FileExists = True
- End If
- End Function
- ' التأكد من وجود دليل أو مجلد
- Public Function DirectoryExists(ByVal APath As String) As Boolean
- Dim Result As String
- Result = Dir(APath, vbDirectory Or vbHidden)
- If Result = "" Then
- DirectoryExists = False
- Else
- DirectoryExists = True
- End If
- End Function
نرجو الاستفادة و السلام.
وَ قُلِ اعْمَلُوا فَسَيَرَى اللهُ عَمَلَكُمْ وَ رَسُولُهُ وَ الْمُؤْمِنُونَ
صدق الله العظيم
لا استيطيع طبيق هذه الوحدة النمطية امل تطبيقها على المثال وشكراً
السلام عليكم...
انسخ الكود التالي و ألصقه في صفحة كود الـ Form ثم شغل البرنامج:
- Private Function ExtractFilePath(ByVal APath As String) As String
- Dim Index As Long
- Dim LastSlashPos As Long
- Dim AChar As String
- Dim ThePath As String
- ThePath = Trim(APath)
- If ThePath = "" Then
- ExtractFilePath = ""
- Else
- LastSlashPos = InStrRev(ThePath, "")
- If LastSlashPos = 0 Then
- ExtractFilePath = ""
- Else
- ExtractFilePath = Left(ThePath, LastSlashPos)
- End If
- End If
- End Function
- Private Sub Command1_Click()
- Text2.Text = ExtractFilePath(Text1.Text)
- End Sub
نرجو الاستفادة و السلام.
تم تعديل هذه المشاركة بواسطة najy_zl في 8 أكتوبر 2009 في 16:51
وَ قُلِ اعْمَلُوا فَسَيَرَى اللهُ عَمَلَكُمْ وَ رَسُولُهُ وَ الْمُؤْمِنُونَ
صدق الله العظيم
الف شكر هذا هو المطلوب