开发者

IsFile, IsDirectory Test Windows

I'm tryin开发者_如何转开发g to convert a program from Linux to use on Windows, and it calls test -f, or test -d on Linux. I need it to do the same thing on Windows. Is there a built-in command, or another program I can use to do the same thing?

I'm programming using FreeBASIC (horrible, but it's what I got).

EDIT: An external program is the best option here. I've looked at the API, and it's not good.


Never heard of FreeBasic before but looking at the help there's a DIR command that supports using fbDirectory as one of the attribute patterns to filter for.
And looking slightly further down on that page I just saw that they have a sample for checking if the objects found are files or directories. Just look here, look at the second example on that page.

Not sure what exactly those test commands do, but if you want to test if a specific object is a directory you should be able to call Dir("exactname", fbDirectory, something) I'd thought. And then you could test for a file by putting a Not in somewhere (assuming that FreeBasic supports that).

Edit: To make your own tool, here's a sample that shows a tiny C++ app that could easily be changed to look for directories or not. Look for the FindFirstFile in the sample and shortly after that it checks if it's readonly, which could be changed for FILE_ATTRIBUTE_DIRECTORY.


http://unxutils.sourceforge.net/

you can use test.exe just like under linux


Not sure about FreeBASIC, have you looked into vbscript? You could use the FileSystemObject

Dim fso, msg
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FolderExists(fldr)) Then
   'Do Something here
Else
   'Do Something
End If
If (fso.FileExists(filespec)) Then
   'Do Something here
Else
   'Do Something
End If


You can also use Kiwi for FreeBasic in order to check if a path leads to a file or directory. You can find Kiwi on Github (https://github.com/nsiatras/kiwi)

#include once "kiwi\kiwi.bi"
#include once "kiwi\io.bi"

' Declare a new file
Dim myFile as File = File("C:\Users\nsiat\Desktop\Test.txt")

' Check if file exists, is a File or is a Directory
print "File exists: " & myFile.exists()
print "Is file: " & myFile.isFile()
print "Is Directory: " & myFile.isDirectory()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜