Sign in to follow this  
Followers 0
spyrorocks

Direxists() Function

18 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

nice... but

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

late again... JdeB got there first

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

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 :)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

it does too. try it. it works perfecly.

Doing things in 3 lines is no fun.

initial post...

This post has been edited by spyrorocks: Today, 12:22 PM

it does now

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#10 ·  Posted

@ spyrorocks

please note...

because of your signature with html links.. etc

when ever i am on a thread that you have posted on... my mouse-pointer has an hour-glass showing the page has not finished loading...

please fix that

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#12 ·  Posted

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.

Share this post


Link to post
Share on other sites

#14 ·  Posted

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()... :)

[center]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.[/center]

Share this post


Link to post
Share on other sites

#15 ·  Posted

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

Share this post


Link to post
Share on other sites

#16 ·  Posted

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 :)

[center]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.[/center]

Share this post


Link to post
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)

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  
Followers 0