Jump to content
Sign in to follow this  
tony01

How can I recognize a Folder?

Recommended Posts

tony01

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.

Share this post


Link to post
Share on other sites
Somerset

FileGetAttrib


 

Spoiler

 

Share this post


Link to post
Share on other sites
jvanegmond

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

Share this post


Link to post
Share on other sites
Somerset

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

 

Spoiler

 

Share this post


Link to post
Share on other sites
jvanegmond

what if their windows root directy is winnt, not windows? :) nitpick...

Then the function still works, nitpick. :)

Share this post


Link to post
Share on other sites
tony01

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

Share this post


Link to post
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
Sign in to follow this  

×