Jump to content

[SOLVED] Determine if item is a file or dir


Recommended Posts

Hello! I got a very basic script that list files in a folder.

#include <File.au3>

$Folder = "C:\Users\[NAME]\Desktop\"

$FileList = _FileListToArray($Folder)

For $i = 1 to $FileList[0]
    $FileList[$i]
Next

I would like to know if each found item is a file or folder. I was thinking about checking if the file had an extension, like...

FileGetExtension("File.ext")

Func _FileGetExtension($iFile)
    $iFileArray = StringSplit($iFile,".")
    Return $iFileArray[$iFileArray[0]]
EndFunc

But then I remembered that both a folder can contain a dot and a file can miss the extension.

Any ideas how I can do this?

Edited by Vossen
Link to comment
Share on other sites

Hello! I got a very basic script that list files in a folder.

#include <File.au3>

$Folder = "C:\Users\Stig Voss\Desktop\"

$FileList = _FileListToArray($Folder)

For $i = 1 to $FileList[0]
    $FileList[$i]
Next

I would like to know if each found item is a file or folder. I was thinking about checking if the file had an extension, like...

FileGetExtension("File.ext")

Func _FileGetExtension($iFile)
    $iFileArray = StringSplit($iFile,".")
    Return $iFileArray[$iFileArray[0]]
EndFunc

But then I remembered that both a folder can contain a dot and a file can miss the extension.

Any ideas how I can do this?

Use flags from _FileListToArray():

#include <File.au3>
#include <Array.au3>
$DIRS = _FileListToArray(@ScriptDir,"*",2)
$FILES = _FileListToArray(@ScriptDir,"*",1)
_ArrayDisplay($FILES)
_ArrayDisplay($DIRS)
Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

Use flags from _FileListToArray():

#include <File.au3>
#include <Array.au3>
$DIRS = _FileListToArray(@ScriptDir,"*",2)
$FILES = _FileListToArray(@ScriptDir,"*",1)
_ArrayDisplay($FILES)
_ArrayDisplay($DIRS)
Thank you, Andreik.

How stupid can you be? Why didn't I search File.au3, the most obvious place?

Thanks again!

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...