1. Sudeep Pandey
  2. PowerBuilder
  3. Monday, 11 March 2019 10:13 AM UTC

Hello,

I am using PB 2017 R3 Build 1880.

The FileDelete function is working fine in my machine whenever my application run on other machine then it is not getting deleted. I assume this function is returning (FALSE or NULL).

That might the file access or other issue.

I just want to display a proper message to user, why this file is not deleting like (Access denied or file is in used ,...etc.)

 

ls_file_loc variable has correct file location. 

 

IF FileDelete (ls_file_loc) <> TRUE then
   Messagebox("Info", "Unable to delete file", Exclamation!, OK! )
END IF

 

Please give your valuable suggestion...

 

Roland Smith Accepted Answer Pending Moderation
  1. Monday, 11 March 2019 14:34 PM UTC
  2. PowerBuilder
  3. # 1

The file may be ReadOnly. In that case you need to change the attributes.

Function boolean SetFileAttributes ( &
             string lpFileName, &
             ulong dwFileAttributes &
             ) Library "kernel32.dll" Alias For "SetFileAttributesW"

 

SetFileAttributes(ls_filename, 0)

FileDelete(ls_filename)

 

Comment
There are no comments made yet.
Brad Mettee Accepted Answer Pending Moderation
  1. Monday, 11 March 2019 13:44 PM UTC
  2. PowerBuilder
  3. # 2

We need some more info:

Where is the file being created?

Does the user running the application have delete rights to the file? Delete rights to the directory?

 

You can get the last error from the OS, and format a system message from it:

// these declarations & code are slightly modified versions from n_runandwait object
// local external functions
// GetLastError & FormatMessage used to determine cause of failed system operation
Function ulong GetLastError( ) Library "kernel32.dll"

Function ulong FormatMessage( &
ulong dwFlags, &
ulong lpSource, &
ulong dwMessageId, &
ulong dwLanguageId, &
Ref string lpBuffer, &
ulong nSize, &
ulong Arguments &
) Library "kernel32.dll" Alias For "FormatMessageW"

code:

Constant ULong FORMAT_MESSAGE_FROM_SYSTEM = 4096
Constant ULong LANG_NEUTRAL = 0

unsigned long lul_lasterror
lul_lasterror= GetLastError()

ULong lul_rtn
String ls_msgtext

ls_msgtext = Space(255)

lul_rtn = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, &
lul_lasterror, LANG_NEUTRAL, ls_msgtext, Len(ls_msgtext), 0)

ls_msgtext = Trim(ls_msgtext)

ls_msgtext will contain a windows style error message.

Comment
  1. Sudeep Pandey
  2. Tuesday, 12 March 2019 12:41 PM UTC
Thank you for reply...

Actually this file is creating by vb script. This vb script is executing in my PB application through RUN method. This file is creating in same directory where PB Application is running. Normally it is running in E:\ Drive.



I applied your suggested code but it is displaying message "The specified module could not be found" but I can see file is there. I just want popup the message why this file not getting deleted like Access denied or other.



Thank you.

  1. Helpful
  1. Chris Pollach @Appeon
  2. Tuesday, 12 March 2019 19:09 PM UTC
FWIW: Sounds like a "File Lock" is still in effect (just my guess) from the VB creation.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.