Re: make dir in win32

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hi There Aku,

I modified Win32fil.ew buy Jeffrey Fielding to add the Create Directory API
call.

The following is the modified Version of win32fil.ew

----------------------

-- Win32 file functions by Jeffrey Fielding (JJProg at cyberbury.net)
-- All return 1 if success, 0 if not
-- success = DeleteFile(filename)
-- success = MoveFile(old, new)
-- success = CopyFile(old, new, failIfExists)
-- failIfExists is 1 if you want it to cancel if new already exists
--                 0 if you want it to overwrite new

--modified by Ray Smith to add CreateDirectory 20-Sept-2000
--
include dll.e
include machine.e
constant KERNEL32 = open_dll("kernel32")
if KERNEL32 = 0 then
    puts(1,"Couldn't open kernel32.dll.\n")
    abort(1)
end if
constant pDeleteFile = define_c_func(KERNEL32,"DeleteFileA",
{C_POINTER},C_LONG)
constant pMoveFile = define_c_func(KERNEL32,"MoveFileA",
{C_POINTER,C_POINTER},
    C_LONG)
constant pCopyFile = define_c_func(KERNEL32,"CopyFileA",
{C_POINTER,C_POINTER,
    C_LONG},C_LONG)
constant pCreateDirectory = define_c_func(KERNEL32, "CreateDirectoryA",
    {C_POINTER, C_POINTER}, C_INT)

constant pGetTempPath = define_c_func(KERNEL32, "GetTempPathA",
    {C_LONG, C_POINTER}, C_INT)

-------------------------------------
-- peek_sequence
-------------------------------------
function peek_sequence(atom addr, integer len)
   integer i, tmp
   sequence seq

   seq=""
   i=0
   tmp=peek(addr)
   while (tmp != 0 and i<len) do
      seq = append(seq, tmp)
      i = i + 1
      tmp = peek(addr+i)
   end while
   return seq

end function


global function DeleteFile(sequence name)
    atom a
    object r
    a = allocate_string(name)
    r = c_func(pDeleteFile,{a})
    free(a)
    return r
end function
global function MoveFile(sequence exists, sequence new)
    atom a, b
    object r
    a = allocate_string(exists)
    b = allocate_string(new)
    r = c_func(pMoveFile,{a,b})
    free(a)
    free(b)
    return r
end function
global function CopyFile(sequence exists, sequence new, integer
failIfExists)
    atom a, b
    object r
    a = allocate_string(exists)
    b = allocate_string(new)
    r = c_func(pCopyFile,{a,b,failIfExists})
    free(a)
    free(b)
    return r
end function
global function CreateDirectory(sequence dir)
    atom a
    integer r

    a = allocate_string(dir)
    r = c_func(pCreateDirectory,{a, NULL})
    free(a)
    return r
end function
global function GetTempPath()
   atom a
   sequence temp_path
   integer l, r
   l = 255

   a = allocate(l)
   r = c_func(pGetTempPath, {l, a})
   temp_path = peek_sequence(a, l)
   free(a)
   return {r, temp_path}
end function

-----------------------

To use it all you have to do is:


include win32fil.ew
...
if CreateDirectory("c:\\tmp\\new_dir") then
-- it worked
else
-- it didn't work
end if


Hope Jeffrey doesn't mind I modified his include file???

Hope this helps,

Ray Smith



On Sun, 8 Oct 2000 12:08:10 +0700, Aku <aku at INBOX.AS> wrote:

>Ditulis 8-10-2000, 12:06 pake kalong
>
> How i can make a directory in win32?
>
> if i use system("mkdir abc", 0) it opens a ms dos window anda i must
> close  it.  so  how i can do that without opening ms dos window? the
> same problem for delete, rename, copy, etc
>
>
>
>
>--
>Aku

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu