Jump to content
Sign in to follow this  
Vossen

[SOLVED] Determine if item is a file or dir

Recommended Posts

Vossen

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

Share this post


Link to post
Share on other sites
Andreik

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

Share this post


Link to post
Share on other sites
Vossen

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!

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.