Jump to content

How can I recognize a Folder?


Recommended Posts

Hi everybody:

This is the situation :

I have many paths and I want to identify which ones are folders, All the paths already exists.

Example:

c:\@---- BOOKS ----\Formulas.and.Functions.With.Microsoft.Excel.003

c:\@---- BOOKS ----\Microsoft.Excel.sol

C:\Program Files\XP Repair Pro 2007\XPRepairPro.exe

The first, and the second one are folders, the last one is a file.

Is there an Autoit Function or script to know if the path is a folder?

Thanks

Rudolph.

Link to comment
Share on other sites

If PathIsDir("C:\") Then
    MsgBox(0, "", "C:\ is a dir")
Else
    MsgBox(0, "", "C:\ is a file")
EndIf

If PathIsDir("C:\Windows\Explorer.exe") Then
    MsgBox(0, "", "C:\Windows\Explorer.exe is a dir")
Else
    MsgBox(0, "", "C:\Windows\Explorer.exe is a file")
EndIf


Func PathIsDir($s_Path) ; if the path entered is a directory, it returns a number bigger then zero. If it is not it returns 0.
    $s_Attrib = FileGetAttrib($s_Path)
    Return StringInStr($s_Attrib,"D",1)
EndFunc

Link to comment
Share on other sites

If PathIsDir("C:\") Then
    MsgBox(0, "", "C:\ is a dir")
Else
    MsgBox(0, "", "C:\ is a file")
EndIf

If PathIsDir("C:\Windows\Explorer.exe") Then
    MsgBox(0, "", "C:\Windows\Explorer.exe is a dir")
Else
    MsgBox(0, "", "C:\Windows\Explorer.exe is a file")
EndIf
Func PathIsDir($s_Path) ; if the path entered is a directory, it returns a number bigger then zero. If it is not it returns 0.
    $s_Attrib = FileGetAttrib($s_Path)
    Return StringInStr($s_Attrib,"D",1)
EndFunc
what if their windows root directy is winnt, not windows? :) nitpick... Edited by beerman
Link to comment
Share on other sites

Thanks beerman ,

FileGetAttrib is working like a charm.

Manadar, cool script, I modified a little bit:

Dim $path = "c:\@---- BOOKS ----\Formulas.and.Functions.With.Microsoft.Excel.003"
If PathIsDir($path) Then
    MsgBox(0, "", $path &  "  is a Directory")
Else
    MsgBox(0, "", $path &  "  is a File")
EndIf


Func PathIsDir($s_Path) ; if the path entered is a directory, it returns a number bigger then zero. If it is not it returns 0.
    $s_Attrib = FileGetAttrib($s_Path)
    Return StringInStr($s_Attrib,"D",1)
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...