1. make dir in win32

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     » topic index » view message » categorize

2. Re: make dir in win32

C function "CreateDirectory" does that but it's not  in win32lib.

You define it like this:
    iCreateDirectory =

Maybe this function will do that, i don't know, i never tested it, it's not
mine:

global function create_directory(sequence x)
integer location, lastlocation, found, ok,errorCode
atom name
sequence directory
found = 0
lastlocation = 0
directory={0,0}
        x = x[8..length(x)]
        while 1 do
            location = find('/',x)
            if location = 0 and found = 0 then
                name = allocate_string(x)
                ok = c_func(iCreateDirectory,{name,0})
                if ok = 0 then
                    errorCode = c_func(iGetLastError,{})
                    if errorCode = 183 then
                    else
                    alertmsg("Can't create directory. Error code is " &
                        sprintf("%d", errorCode))
                    free(name)
                    directory = {0,0}
                    return directory
                    end if
                end if
                free(name)
                x = x & "\\"
                lastlocation = length(x)
                exit
            elsif location = 0 then
                exit
            end if
            x[location] = '\\'
            name = allocate_string(x[1..location-1])
            ok = c_func(iCreateDirectory,{name,0})
            if ok = 0 then
                errorCode = c_func(iGetLastError,{})
                if errorCode = 183 then
                else
                    alertmsg("Can't create directory. Error code is " &
                        sprintf("%d", errorCode))
                    free(name)
                    directory = {0,0}
                    return directory
                end if
            end if
            free(name)
            found = found + 1
            lastlocation = location
        end while
        if length(x) = lastlocation then
            directory[1] = x
            directory[2] = "default.htm"
            return directory
        end if
        directory[1] = x[1..lastlocation]
        directory[2] = x[lastlocation+1..length(x)]
        return directory
end function

new topic     » goto parent     » topic index » view message » categorize

3. Re: make dir in win32

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 message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu