1. system() help

I'm using system(rmdir.....) in a loop deleting directories but get a black screen flashing each time it executes. Is there another way to loop without flashing the black screen? I would just like it to delete the stuff w/o any screen feedback. How can I do this? thanks for any ideas.

new topic     » topic index » view message » categorize

2. Re: system() help

GeorgeWalters said...

I'm using system(rmdir.....) in a loop deleting directories but get a black screen flashing each time it executes. Is there another way to loop without flashing the black screen? I would just like it to delete the stuff w/o any screen feedback. How can I do this? thanks for any ideas.

I guess you are using exw.exe ?

Try system("start /b rmdir ...", 2) - that should avoid a flashing screen.

Why are you using system() for this anyways?

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

3. Re: system() help

jimcbrown said...
GeorgeWalters said...

I'm using system(rmdir.....) in a loop deleting directories but get a black screen flashing each time it executes. Is there another way to loop without flashing the black screen? I would just like it to delete the stuff w/o any screen feedback. How can I do this? thanks for any ideas.

I guess you are using exw.exe ?

Try system("start /b rmdir ...", 2) - that should avoid a flashing screen.

Why are you using system() for this anyways?

It was the only way I could think of. system_exec would not work with rmdir... but it might with your idea of using start. I"ll try it. thanks

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

4. Re: system() help

Well, It doesen't work with rmdir. Perhaps because it's an internal command to DOS? Here's the code.

system("start /b rmdir /s /q " & targetRoot & str(i), 2)

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

5. Re: system() help

GeorgeWalters said...

Well, It doesen't work with rmdir. Perhaps because it's an internal command to DOS? Here's the code.

system("start /b rmdir /s /q " & targetRoot & str(i), 2)

If thats because its an internal command, then this may work:

system("start /b cmd /c rmdir /s /q " & targetRoot & str(i), 2)

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

6. Re: system() help

Well, that did not work either. Says something in a black screen too fast to read.

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

7. Re: system() help

Can you use the Win32 API and it's targeting a win NT based platform? If that's the case, you can use RemoveDirectory ( http://msdn.microsoft.com/en-us/library/aa365488.aspx ).

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

8. Re: system() help

gbonvehi said...

Can you use the Win32 API and it's targeting a win NT based platform? If that's the case, you can use RemoveDirectory ( http://msdn.microsoft.com/en-us/library/aa365488.aspx ).

That is over my head, but anyway the directory must be empty and mine are not. I guess I'll just have to put up with the flashing black screens.

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

9. Re: system() help

GeorgeWalters said...

Well, that did not work either. Says something in a black screen too fast to read.

May need additional options.

Try "start /b /wait /min cmd /c rmdir ..."

The full list of options to start is at:

http://www.computerhope.com/starthlp.htm

Failing that, you could try run.exe from the cygwin distribution (mingw might have a version as well) which is suppose to be designed to run programs with the console window hidden.

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

10. Re: system() help

I could not find a link separate from cygwin, the best i could do was this:

http://www.mail-archive.com/cygwin-apps@cygwin.com/msg15370.html

jimcbrown said...
GeorgeWalters said...

Well, that did not work either. Says something in a black screen too fast to read.

May need additional options.

Try "start /b /wait /min cmd /c rmdir ..."

The full list of options to start is at:

http://www.computerhope.com/starthlp.htm

Failing that, you could try run.exe from the cygwin distribution (mingw might have a version as well) which is suppose to be designed to run programs with the console window hidden.

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

11. Re: system() help

The solution here SHFileOperation. I noticed it's not in Win32Lib. I'll throw together an example and post it up in a bit.

-Greg

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

12. Re: system() help

i use this code to add and remove directories - uses api calls

-- ************************************************************************** 
-- CreateDir and RemoveDir based on Jeffrey Fielding's code found in win32fil.zip 
 
constant KERNEL32 = open_dll("kernel32") 
if KERNEL32 = 0 then 
    puts(1,"Couldn't open kernel32.dll.\n") 
    abort(1) 
end if 
 
-- success = CreateDir(tocreate,securityinfo) 
--  note: always pass "" as second parameter 
-- success = RemoveDir(toremove) 
constant pCreateDir = define_c_func(KERNEL32,"CreateDirectoryA",{C_POINTER,C_INT}, 
    C_LONG) 
 
constant pRemoveDir = define_c_func(KERNEL32,"RemoveDirectoryA",{C_POINTER},C_LONG) 
 
global function CreateDir(sequence tocreate, sequence security) 
    atom a, b 
    object r 
    a = allocate_string(tocreate) 
    b = allocate_string(security) 
    --r = c_func(pCreateDir,{a,b}) 
    -- pass it a null as the security pointer and it works fine 
    r = c_func(pCreateDir,{a,0}) 
    free(a) 
    free(b) 
    return r 
end function 
 
global function RemoveDir(sequence toremove) 
    atom a 
    object r 
    a = allocate_string(toremove) 
    r = c_func(pRemoveDir,{a}) 
    free(a) 
    return r 
end function 
-- ************************************************************************** 
 
new topic     » goto parent     » topic index » view message » categorize

13. Re: system() help

Well, after some hours at work without work (actually 3 days by now, just changed job :/ ), I crafted this.. :)

include machine.e 
include dll.e 
 
constant wKernel32 = open_dll("kernel32.dll") 
constant wDeleteFile = define_c_func(wKernel32, "DeleteFileA", {C_POINTER},  
C_LONG) 
constant wFindFirstFile = define_c_func(wKernel32, "FindFirstFileA", {C_POINTER,  
C_POINTER}, C_POINTER) 
constant wFindNextFile = define_c_func(wKernel32, "FindNextFileA", {C_POINTER,  
C_POINTER}, C_LONG) 
constant wFindClose = define_c_func(wKernel32, "FindClose", {C_POINTER}, C_LONG) 
constant wRemoveDirectory = define_c_func(wKernel32, "RemoveDirectoryA", {C_POINTER}, C_LONG) 
 
constant wFILE_ATTRIBUTE_DIRECTORY = 16 
constant wINVALID_HANDLE_VALUE = -1 
 
constant sizeOfDWORD = 4 
constant wMAX_PATH = 260 
 
function peek_string(atom addr, atom maxbytes) 
    sequence text 
    atom chr 
    maxbytes += addr 
    text = {} 
    if addr > 0 then 
        chr = peek(addr) 
        while chr != 0 and addr < maxbytes do 
            text = text & chr 
            addr += 1 
            chr = peek(addr) 
        end while 
    end if 
    return text 
end function 
 
function deleteFile(sequence name) 
    atom pname 
    atom ret 
 
    pname = allocate_string(name) 
 
    ret = c_func(wDeleteFile,{pname}) 
     
    free(pname) 
     
    return ret 
end function 
 
--typedef struct _FILETIME { 
--  DWORD dwLowDateTime; 
--  DWORD dwHighDateTime; 
--} FILETIME,  
-- *PFILETIME; 
constant sizeOfFILETIME = sizeOfDWORD * 2 
function allocate_FILETIME() 
    atom pFILETIME 
     
    pFILETIME = allocate(sizeOfFILETIME) 
     
    return pFILETIME 
end function 
 
--typedef struct _WIN32_FIND_DATA { 
--  DWORD dwFileAttributes; 
--  FILETIME ftCreationTime; 
--  FILETIME ftLastAccessTime; 
--  FILETIME ftLastWriteTime; 
--  DWORD nFileSizeHigh; 
--  DWORD nFileSizeLow; 
--  DWORD dwReserved0; 
--  DWORD dwReserved1; 
--  TCHAR cFileName[MAX_PATH]; 
--  TCHAR cAlternateFileName[14]; 
--} WIN32_FIND_DATA,  
-- *PWIN32_FIND_DATA,  
-- *LPWIN32_FIND_DATA; 
constant sizeOfWIN32_FIND_DATA = sizeOfDWORD * 7 + sizeOfFILETIME * 3 +  
wMAX_PATH + 14 
constant WIN32_FIND_DATA_dwFileAttributes = 0 
constant WIN32_FIND_DATA_cFileName =  sizeOfFILETIME * 3 + sizeOfDWORD * 5 
function allocate_WIN32_FIND_DATA() 
    atom pWIN32FINDDATA 
     
     
    pWIN32FINDDATA = allocate(sizeOfWIN32_FIND_DATA) 
     
    return pWIN32FINDDATA 
end function 
 
function findFirstFile(sequence file, atom pwin32finddata) 
    atom fHandle, pfile 
    pfile = allocate_string(file) 
     
    fHandle = c_func(wFindFirstFile,{pfile, pwin32finddata}) 
     
    free(pfile) 
    return fHandle 
end function 
 
function findNextFile(atom handle, atom pwin32finddata) 
    return c_func(wFindNextFile,{handle, pwin32finddata}) 
end function 
 
function findClose(atom handle) 
    return c_func(wFindClose, {handle}) 
end function 
 
global function removeDirectory(sequence name) 
    atom fHandle, pwin32finddata, retval, FileAttributes, pname 
    sequence filename, oriname 
 
    retval = 0 
 
    pwin32finddata = allocate_WIN32_FIND_DATA() 
     
    if length(name) then 
        if name[$] != '\\' then 
            name = name & "\\" 
        end if 
        oriname = name 
        name = name & "*" 
 
        fHandle = findFirstFile(name, pwin32finddata) 
        if fHandle != -1 then 
     
            filename = peek_string(pwin32finddata+WIN32_FIND_DATA_cFileName, 259) 
            poke(pwin32finddata+WIN32_FIND_DATA_cFileName,0) 
             
            if not equal(filename,".") and not equal(filename,"..") then 
                FileAttributes = peek4u(pwin32finddata+WIN32_FIND_DATA_dwFileAttributes) 
                FileAttributes = and_bits(FileAttributes, wFILE_ATTRIBUTE_DIRECTORY) 
                if FileAttributes != 0 then 
                    retval = removeDirectory(oriname & filename) 
                else 
                    retval = deleteFile(oriname & filename) 
                end if 
                if not retval then 
                    fHandle = wINVALID_HANDLE_VALUE 
                end if 
            end if 
            if fHandle != wINVALID_HANDLE_VALUE then 
                while findNextFile(fHandle, pwin32finddata) do 
     
                    filename = peek_string(pwin32finddata+WIN32_FIND_DATA_cFileName, 259) 
                    poke(pwin32finddata+WIN32_FIND_DATA_cFileName,0) 
     
                    if not equal(filename,".") and not equal(filename,"..") then 
                        FileAttributes = peek4u(pwin32finddata+WIN32_FIND_DATA_dwFileAttributes) 
                        FileAttributes = and_bits(FileAttributes, wFILE_ATTRIBUTE_DIRECTORY) 
                        if FileAttributes != 0 then 
                            retval = removeDirectory(oriname & filename) 
                        else 
                            retval = deleteFile(oriname & filename) 
                        end if 
                        if not retval then 
                            exit 
                        end if 
                    end if 
                     
                end while 
                if findClose(fHandle) then end if 
            end if 
             
            pname = allocate_string(name[1..$-1]) 
            retval = c_func(wRemoveDirectory,{pname}) 
            free(pname) 
             
        end if 
 
        free(pwin32finddata) 
 
    end if 
    return retval 
end function 

I tested it and worked, I hope it does for you too :)

Little test:

include removedirectory.ew 
 
procedure listFilesTest() 
    sequence test 
    test =  "c:\\temp\\test\\" 
        if removeDirectory(test) then end if 
    while get_key() = -1 do 
    end while 
end procedure 
 
listFilesTest() 
new topic     » goto parent     » topic index » view message » categorize

14. Re: system() help

I just posted my wrapper for SHFileOperation to The Archive.

--shfile.ew 
 
include Win32Lib.ew 
 
-- SHFileOperation Function 
-- http://msdn.microsoft.com/en-us/library/bb762164(VS.85).aspx 
 
global constant  
    xSHFileOperation    = registerw32Function( shell32, "SHFileOperationA", {C_POINTER}, C_INT ) 
 
global constant  
    -- possible return values for SHFileOperation 
    DE_SAMEFILE         = #71,      -- The source and destination files are the same file. 
    DE_MANYSRC1DEST     = #72,      -- Multiple file paths were specified in the source buffer, but only one destination file path. 
    DE_DIFFDIR          = #73,      -- Rename operation was specified but the destination path is a different directory. Use the move operation instead. 
    DE_ROOTDIR          = #74,      -- The source is a root directory, which cannot be moved or renamed. 
    DE_OPCANCELLED      = #75,      -- The operation was cancelled by the user, or silently cancelled if the appropriate flags were supplied to SHFileOperation. 
    DE_DESTSUBTREE      = #76,      -- The destination is a subtree of the source. 
    DE_ACCESSDENIEDSRC  = #78,      -- Security settings denied access to the source. 
    DE_PATHTOODEEP      = #79,      -- The source or destination path exceeded or would exceed MAX_PATH. 
    DE_MANYDEST         = #7A,      -- The operation involved multiple destination paths, which can fail in the case of a move operation. 
    DE_INVALIDFILES     = #7C,      -- The path in the source or destination or both was invalid. 
    DE_DESTSAMETREE     = #7D,      -- The source and destination have the same parent folder. 
    DE_FLDDESTISFILE    = #7E,      -- The destination path is an existing file. 
    DE_FILEDESTISFLD    = #80,      -- The destination path is an existing folder. 
    DE_FILENAMETOOLONG  = #81,      -- The name of the file exceeds MAX_PATH. 
    DE_DEST_IS_CDROM    = #82,      -- The destination is a read-only CD-ROM, possibly unformatted. 
    DE_DEST_IS_DVD      = #83,      -- The destination is a read-only DVD, possibly unformatted. 
    DE_DEST_IS_CDRECORD = #84,      -- The destination is a writable CD-ROM, possibly unformatted. 
    DE_FILE_TOO_LARGE   = #85,      -- The file involved in the operation is too large for the destination media or file system. 
    DE_SRC_IS_CDROM     = #86,      -- The source is a read-only CD-ROM, possibly unformatted. 
    DE_SRC_IS_DVD       = #87,      -- The source is a read-only DVD, possibly unformatted. 
    DE_SRC_IS_CDRECORD  = #88,      -- The source is a writable CD-ROM, possibly unformatted. 
    DE_ERROR_MAX        = #B7,      -- MAX_PATH was exceeded during the operation. 
    DE_ERROR_UNKNOWN    = #402,     -- An unknown error occurred. This is typically due to an invalid path in the source or destination. This error does not occur on Windows Vista and later. 
    ERRORONDEST         = #10000    -- An unspecified error occurred on the destination. 
 
global constant  
    -- SHFILEOPSTRUCT 
    shfo_hwnd               = w32allot( Long ), 
    shfo_wFunc              = w32allot( Long ), 
    shfo_pFrom              = w32allot( Lpsz ), 
    shfo_pTo                = w32allot( Lpsz ), 
    shfo_fFlags             = w32allot( Long ), 
    shfo_fAnyOperationsAborted = w32allot( Long ), 
    shfo_hNameMappings      = w32allot( Ptr ), 
    shfo_lpszProgressTitle  = w32allot( Lpsz ), 
    SIZEOF_SHFILEOPSTRUCT   = w32allotted_size() 
 
global constant  
    -- values for wFunc 
    FO_MOVE     = 1, 
    FO_COPY     = 2, 
    FO_DELETE   = 3, 
    FO_RENAME   = 4 
 
global constant  
    -- values for fFlags 
    FOF_MULTIDESTFILES          =    1, 
    FOF_CONFIRMMOUSE            =    2, 
    FOF_SILENT                  =    4, 
    FOF_RENAMEONCOLLISION       =    8, 
    FOF_NOCONFIRMATION          =   16, 
    FOF_WANTMAPPINGHANDLE       =   32, 
    FOF_ALLOWUNDO               =   64, 
    FOF_FILESONLY               =  128, 
    FOF_SIMPLEPROGRESS          =  256, 
    FOF_NOCONFIRMMKDIR          =  512, 
    FOF_NOERRORUI               = 1024, 
    FOF_NOCOPYSECURITYATTRIBS   = 2048, 
    FOF_NO_UI = w32or_all( FOF_SILENT & FOF_NOCONFIRMATION & FOF_NOERRORUI & FOF_NOCONFIRMMKDIR ) 
 
global function SHFileOperation( integer pId, atom wFunc, sequence pFrom, sequence pTo, atom fFlags, sequence szProgressTitle ) 
-- returns 0 if successful, -1 if the operation was canceled, or (hopefully) one of the DE_ constants above 
 
    atom mset, hWnd, lpFrom, lpTo, lpszProgressTitle, shfo, ret 
     
    mset = w32new_memset() 
     
    if length(pFrom) and pFrom[$] != 0 then 
        pFrom &= 0 
    end if 
 
    if length(pTo) and pTo[$] != 0 then 
        pTo &= 0 
    end if 
     
    hWnd = NULL 
    if pId then 
        hWnd = getHandle( pId ) 
    end if 
     
    lpFrom = w32acquire_mem( mset, pFrom & 0 ) 
    lpTo = w32acquire_mem( mset, pTo & 0 ) 
    lpszProgressTitle = w32acquire_mem( mset, szProgressTitle & 0 ) 
     
    shfo = w32acquire_mem( mset, SIZEOF_SHFILEOPSTRUCT ) 
    w32store( shfo, shfo_hwnd, hWnd ) 
    w32store( shfo, shfo_wFunc, wFunc ) 
    w32store( shfo, shfo_pFrom, lpFrom ) 
    w32store( shfo, shfo_pTo, lpTo ) 
    w32store( shfo, shfo_fFlags, fFlags ) 
    w32store( shfo, shfo_fAnyOperationsAborted, NULL ) 
    w32store( shfo, shfo_hNameMappings, NULL ) 
    w32store( shfo, shfo_lpszProgressTitle, lpszProgressTitle ) 
     
    ret = w32Func( xSHFileOperation, {shfo} ) 
    if ret = 0 then 
        -- potentially successful, check for abort 
         
        ret = w32fetch( shfo, shfo_fAnyOperationsAborted ) 
        if ret != 0 then 
            ret = -1 
        end if 
         
    end if 
     
    w32release_mem( mset ) 
     
    return ret 
end function 

-Greg

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

15. Re: system() help

Wow, nice work Greg, I think he should use that wrapper heh :) Mine actually wraps removeDirectory, but also does a recursive file deletion inside it if it's not empty. I could have used euphoria's dir() routine (in case someone is thinking about that), but well, I was wrapping one thing... and I was tempted by another.. heh

I discovered a little bug in my code (ugly actually forgot to allocate FILETIME), I'll post an updated copy just in case. I also added the open_dll test just to make it prettier :) Oh, also two comment lines with the description of the function.

nclude machine.e 
include dll.e 
 
constant 
    wKernel32 = open_dll("kernel32.dll"), 
    wDeleteFile = define_c_func(wKernel32, "DeleteFileA", {C_POINTER}, C_LONG), 
    wFindFirstFile = define_c_func(wKernel32, "FindFirstFileA", {C_POINTER, C_POINTER}, C_POINTER), 
    wFindNextFile = define_c_func(wKernel32, "FindNextFileA", {C_POINTER, C_POINTER}, C_LONG), 
    wFindClose = define_c_func(wKernel32, "FindClose", {C_POINTER}, C_LONG), 
    wRemoveDirectory = define_c_func(wKernel32, "RemoveDirectoryA", {C_POINTER}, C_LONG), 
    wFILE_ATTRIBUTE_DIRECTORY = 16, 
    wINVALID_HANDLE_VALUE = -1, 
 
    sizeOfDWORD = 4, 
    wMAX_PATH = 260 
 
function peek_string(atom addr, atom maxbytes) 
    sequence text 
    atom chr 
    maxbytes += addr 
    text = {} 
    if addr > 0 then 
        chr = peek(addr) 
        while chr != 0 and addr < maxbytes do 
            text = text & chr 
            addr += 1 
            chr = peek(addr) 
        end while 
    end if 
    return text 
end function 
 
function deleteFile(sequence name) 
    atom pname 
    atom ret 
 
    pname = allocate_string(name) 
 
    ret = c_func(wDeleteFile,{pname}) 
     
    free(pname) 
     
    return ret 
end function 
 
constant 
    sizeOfFILETIME = sizeOfDWORD * 2 
     
function allocate_FILETIME() 
    atom pFILETIME 
     
    pFILETIME = allocate(sizeOfFILETIME) 
     
    return pFILETIME 
end function 
 
constant 
    sizeOfWIN32_FIND_DATA = sizeOfDWORD * 7 + sizeOfFILETIME * 3 + wMAX_PATH + 14, 
    WIN32_FIND_DATA_dwFileAttributes = 0, 
    WIN32_FIND_DATA_ftCreationTime = 4, 
    WIN32_FIND_DATA_ftLastAccessTime = 8, 
    WIN32_FIND_DATA_ftLastWriteTime = 12, 
    WIN32_FIND_DATA_cFileName =  sizeOfFILETIME * 3 + sizeOfDWORD * 5 
     
function allocate_WIN32_FIND_DATA(sequence FILETIMEstructs) 
    atom pWIN32FINDDATA 
    pWIN32FINDDATA = 0 
    if length(FILETIMEstructs) = 3 then 
        for I = 1 to 3 do 
            if FILETIMEstructs[I] = 0 then 
                return 0 
            end if 
        end for 
        pWIN32FINDDATA = allocate(sizeOfWIN32_FIND_DATA) 
        poke(pWIN32FINDDATA+WIN32_FIND_DATA_ftCreationTime,FILETIMEstructs[1]) 
        poke(pWIN32FINDDATA+WIN32_FIND_DATA_ftLastAccessTime,FILETIMEstructs[2]) 
        poke(pWIN32FINDDATA+WIN32_FIND_DATA_ftLastWriteTime,FILETIMEstructs[3]) 
    end if 
    return pWIN32FINDDATA 
end function 
 
function findFirstFile(sequence file, atom pwin32finddata) 
    atom fHandle, pfile 
    pfile = allocate_string(file) 
     
    fHandle = c_func(wFindFirstFile,{pfile, pwin32finddata}) 
     
    free(pfile) 
    return fHandle 
end function 
 
function findNextFile(atom handle, atom pwin32finddata) 
    return c_func(wFindNextFile,{handle, pwin32finddata}) 
end function 
 
function findClose(atom handle) 
    return c_func(wFindClose, {handle}) 
end function 
 
-- It will stop processing on error returning 0 
-- name must be a path 
 
global function removeDirectory(sequence name) 
    atom fHandle, pwin32finddata, retval, FileAttributes, pname 
    sequence filename, oriname, FILETIMEstructs 
 
    retval = 0 
 
    FILETIMEstructs = {allocate_FILETIME(),allocate_FILETIME(),allocate_FILETIME()} 
    pwin32finddata = allocate_WIN32_FIND_DATA(FILETIMEstructs) 
     
    if length(name) and pwin32finddata != 0 then 
        if name[$] != '\\' then 
            name = name & "\\" 
        end if 
        oriname = name 
        name = name & "*" 
 
        fHandle = findFirstFile(name, pwin32finddata) 
        if fHandle != -1 then 
     
            filename = peek_string(pwin32finddata+WIN32_FIND_DATA_cFileName, 259) 
            poke(pwin32finddata+WIN32_FIND_DATA_cFileName,0) 
             
            if not equal(filename,".") and not equal(filename,"..") then 
                 
                FileAttributes = peek4u(pwin32finddata+WIN32_FIND_DATA_dwFileAttributes) 
                FileAttributes = and_bits(FileAttributes, wFILE_ATTRIBUTE_DIRECTORY) 
                if FileAttributes != 0 then 
                    retval = removeDirectory(oriname & filename) 
                else 
                    retval = deleteFile(oriname & filename) 
                end if 
                 
                if not retval then 
                    fHandle = wINVALID_HANDLE_VALUE 
                end if 
            end if 
            if fHandle != wINVALID_HANDLE_VALUE then 
                while findNextFile(fHandle, pwin32finddata) do 
     
                    filename = peek_string(pwin32finddata+WIN32_FIND_DATA_cFileName, 259) 
                    poke(pwin32finddata+WIN32_FIND_DATA_cFileName,0) 
     
                    if not equal(filename,".") and not equal(filename,"..") then 
                         
                        FileAttributes = peek4u(pwin32finddata+WIN32_FIND_DATA_dwFileAttributes) 
                        FileAttributes = and_bits(FileAttributes, wFILE_ATTRIBUTE_DIRECTORY) 
                        if FileAttributes != 0 then 
                            retval = removeDirectory(oriname & filename) 
                        else 
                            retval = deleteFile(oriname & filename) 
                        end if 
                         
                        if not retval then 
                            exit 
                        end if 
                    end if 
                     
                end while 
                if findClose(fHandle) then end if 
            end if 
             
            pname = allocate_string(name[1..$-1]) 
            retval = c_func(wRemoveDirectory,{pname}) 
            free(pname) 
             
        end if 
 
        for I = 1 to length(FILETIMEstructs) do 
            free(FILETIMEstructs[1])         
        end for 
        free(pwin32finddata) 
 
    end if 
    return retval 
end function 
 
if wKernel32 = 0 then 
    puts(1,"Error on open_dll(\"kernel32.dll\")") 
    abort(1) 
end if 
 
new topic     » goto parent     » topic index » view message » categorize

16. Re: system() help

If somebody could benchmark all this and determine the best method, that would be great. Thanks. smile

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

17. Re: system() help

I hate to say this, but maybe you need it for 3.x, but 4.0 standard library has the functions:

  • file_exists
  • copy_file
  • rename_file
  • delete_file
  • move_file
  • create_directory
  • remove_directory
  • clear_directory -- remove dir recursively

You can look at how they are implemented via the URL:

http://rapideuphoria.svn.sourceforge.net/svnroot/rapideuphoria/trunk/include/std/filesys.e

Jeremy

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

18. Re: system() help

gbonvehi said...

Wow, nice work Greg, I think he should use that wrapper heh :) Mine actually wraps removeDirectory, but also does a recursive file deletion inside it if it's not empty. I could have used euphoria's dir() routine (in case someone is thinking about that), but well, I was wrapping one thing... and I was tempted by another.. heh

The thing about SHFileOperation is that it acts just as if you were performing the operation yourself. So if you FO_DELETE a directory, the whole thing gets deleted automatically. You could also include FOF_ALLOWUNDO to allow the user to reverse your operation, should they be so inclined. blink

-Greg

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

19. Re: system() help

jeremy said...

I hate to say this, but maybe you need it for 3.x, but 4.0 standard library has the functions:

  • file_exists
  • copy_file
  • rename_file
  • delete_file
  • move_file
  • create_directory
  • remove_directory
  • clear_directory -- remove dir recursively

You can look at how they are implemented via the URL:

http://rapideuphoria.svn.sourceforge.net/svnroot/rapideuphoria/trunk/include/std/filesys.e

Jeremy

I'm glad to hear that :) The only problem with remove_directory (WIN32) there, is that it just calls remove directory API function which doesn't delete a directory if it's not empty.

ghaberek said...

The thing about SHFileOperation is that it acts just as if you were performing the operation yourself. So if you FO_DELETE a directory, the whole thing gets deleted automatically. You could also include FOF_ALLOWUNDO to allow the user to reverse your operation, should they be so inclined. blink

-Greg

Even cooler :)

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

20. Re: system() help

gbonvehi said...

I'm glad to hear that :) The only problem with remove_directory (WIN32) there, is that it just calls remove directory API function which doesn't delete a directory if it's not empty.

remove_directory() has that limitation on every platform.

If you want to delete a non-empty directory, use clear_directory()

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

21. Re: system() help

I swear I didn't see that function when I replied :/ Great to see it already done! So, now, instead of Greg's wrapper or mine, he can convert that code and it's done :)

jimcbrown said...

remove_directory() has that limitation on every platform.

If you want to delete a non-empty directory, use clear_directory()

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

22. Re: system() help

Geez, thanks for all the solutions. I'm actually using EU 2.4 and Win32lib 59.1. Quite happy with both of them. Something in the next version of Win32lib broke my code and I haven't had the inclination to redo stuff to upgrade. Maybe I should take another look.

-george

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

23. Re: system() help

Why do you use a DOS command to delete a file under Windows? Any use of DOS willl spawn a console window.

CChris

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

24. Re: system() help

CChris said...

Why do you use a DOS command to delete a file under Windows? Any use of DOS willl spawn a console window.

CChris

What would you suggest I use with 59.1? Perhaps there's more I need to know?

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

25. Re: system() help

Thanks, but I'm stuck in 2.3 and have not needed to upgrade it till now.

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

26. Re: system() help

Well, this one works greate for me. It works with EU 2.3 and Win32Lib 59.1. I get an error (w32allot( long) not declared) using Greg's shfile.e probably because of my old Win32Lib.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu