Jump to content

Direxists() Function


Recommended Posts

I noteced that Autoit does not have a Direxists() function, so me and Joke758 made one.

I searched the fourms for this function and could not find it, so here it is...

Requitements: Autoit version 3

Parameters:

1. Directory to check for existance

Returns:

1 = Success

0 = Failure & Sets @error to 1

Example:

If FileExists("C:\Windows") Then
    MsgBox(4096, "", "exists.")
Else
    MsgBox(4096,"", "does not exist.")
EndIf

Actual Function:

#include <Process.au3>

func direxists($dir)
; Credits: Spyrorocks and Joke758
;=======ENJOY========
$err = _RunDOS("dir " & $dir)
if $err = 0 then 
return 1
else
SetError(1)
return 0
endif
endfunc

Small, But it works!

Edited by spyrorocks
Link to comment
Share on other sites

  • Developers

I noteced that Autoit does not have a Direxists() function, so me and Joke758 made one.

I searched the fourms for this function and could not find it, so here it is...

Requitements: Autoit version 3

Parameters:

1. Directory to check for existance

Returns:

1 = Success

0 = Failure & Sets @error to 1

Example:

$dir = direxists("C:\WINDOWS")
if $dir then 
msgbox(0, "Dir Exists", "Directory Exists!")
else
msgbox(0, "Dir Exists", "Directory Does Not Exist!")
endif

Actual Function:

#include <Process.au3>

func direxists($dir)
; Credits: Spyrorocks and Joke758
;=======ENJOY========
$err = _RunDOS("dir " & $dir)
if $err = 0 then 
return 1
else
SetError(1)
return 0
endfunc

Small, But it works!

Did you test it ?

Think an EndIf is missing

This is even shorter: :)

func direxists($dir)
   Return FileExists($dir)
EndFunc
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Yah, Yah. I know it could have been done in three lines, but where is the fun in that?

Yea right, why make live easy if you can do it the difficult way....

and mine works yours doesn't :)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

it does too. try it. it works perfecly.

Doing things in 3 lines is no fun.

Have you read my post? there is an EndIf missing so the function could error out....

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

K.. now run this and see if you still think your function works nice and fast:

#include <Process.au3>
$x = TimerInit()
ConsoleWrite(" t1:" & direxists1("c:\windows\system") & "   time:" & TimerDiff($x) & @LF)
$x = TimerInit()
ConsoleWrite(" t2:" & direxists2("c:\windows\system") & "   time:" & TimerDiff($x) & @LF)
;
Func direxists1($dir)
    Return FileExists($dir)
EndFunc ;==>direxists1
;
Func direxists2($dir)
; Credits: Spyrorocks and Joke759
;=======ENJOY========
    $err = _RunDOS("dir " & $dir)
    If $err = 0 Then
        Return 1
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc ;==>direxists2

EDIT: Fixed return

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

yes but you could have courtesy and use less images/whatever. I myself do not have dialup but a lot of people do

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

  • Moderators

I noteced that Autoit does not have a Direxists() function, so me and Joke758 made one.

I searched the fourms for this function and could not find it, so here it is...

Requitements: Autoit version 3

Parameters:

1. Directory to check for existance

Returns:

1 = Success

0 = Failure & Sets @error to 1

Example:

If FileExists("C:\Windows") Then
    MsgBox(4096, "", "exists.")
Else
    MsgBox(4096,"", "does not exist.")
EndIf

Actual Function:

#include <Process.au3>

func direxists($dir)
; Credits: Spyrorocks and Joke758
;=======ENJOY========
$err = _RunDOS("dir " & $dir)
if $err = 0 then 
return 1
else
SetError(1)
return 0
endif
endfunc

Small, But it works!

God, I'm so confused, why have even the 3 lines, when the function FileExists() does the same thing anyway? As your clearly showing in your example, your using FileExists() here and your Function name is called DirExists()... :)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Errrr, maybe I'm missing something here, but won't all these functions return TRUE if a FILE exists that isn't a directory like the file "c:\WINDOWS\system32\drivers\etc\hosts" ? Maybe this would be a bit more reliable:

Func DirExists ( $sDirPath )
        If FileExists($sDirPath) AND StringInString(FileGetAttrib($sDirPath), 'D') Then
                Return 1
        Else
                Return 0
        EndIf
EndFunc

Even the DOS Shell calls would return true for the file quoted above. You'd want to add a " /D" parameter to the DIR command, but I don't see the need to shell out for this, and it's probably a lot slower too!

J

Link to comment
Share on other sites

  • Moderators

Errrr, maybe I'm missing something here, but won't all these functions return TRUE if a FILE exists that isn't a directory like the file "c:\WINDOWS\system32\drivers\etc\hosts" ? Maybe this would be a bit more reliable:

Func DirExists ( $sDirPath )
        If FileExists($sDirPath) AND StringInString(FileGetAttrib($sDirPath), 'D') Then
                Return 1
        Else
                Return 0
        EndIf
EndFunc

Even the DOS Shell calls would return true for the file quoted above. You'd want to add a " /D" parameter to the DIR command, but I don't see the need to shell out for this, and it's probably a lot slower too!

J

That's a good point :)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

it does too. try it. it works perfecly.

Doing things in 3 lines is no fun.

I think the exact opposite is true. Doing things in as few lines as possible is fun.

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
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...