Question

I'm trying 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.

Was it helpful?

Solution

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.

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top