views:

66

answers:

3

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.

A: 

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
Ed Gl
If I had not created 2,000 lines of code for Linux, I would be ok with doing it. An external program would work: `exec("isfile filename")`.
bradlis7
+1  A: 

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.

ho1
Yeah, that would be good if it worked 100%. I read somewhere that Dir() is buggy, which is not documented. I will give it a shot.
bradlis7
@bradlis7: If the language features are buggy, you might be better of following Ed's suggestion :). However, if you can execute external executables and get a return value it would be easy to write a tiny exe in C++ or something to look for this (you could probably find some sample code for this easily) and thne just create the tool yourself with some free C++ compiler.
ho1
Well, I ended up using Dir() and fbDirectory. It seems to work. I'm stuck with freebasic, unfortunately...
bradlis7
+1  A: 

http://unxutils.sourceforge.net/

you can use test.exe just like under linux

npocmaka