Page 1 of 1

fileapi.h

Posted: Sat Jul 02, 2022 4:27 pm
by Simo_na
Hello
please, 'help me' and let me understand how to do converting this
https://docs.microsoft.com/en-us/window ... directorya
to Purebasic code.
:|

Re: fileapi.h

Posted: Sat Jul 02, 2022 7:32 pm
by jacdelad

Code: Select all

dir.s="C:\MyDir"
Debug RemoveDirectory_(@dir)
What exactly is your problem?

Re: fileapi.h

Posted: Sat Jul 02, 2022 7:45 pm
by infratec
The link points to RemoveDirectoryA()

'A' means an ASCII string is required.

So ...

Code: Select all

*Ascii = Ascii("c:\MyDir")
RemoveDirectoryA_(*Ascii)
FreeMemory(*Ascii)
But the 'A' version is not directly available in PB.
You have to import it.

And why not DeleteDirectory() :?:

Re: fileapi.h

Posted: Sat Jul 02, 2022 8:16 pm
by Simo_na
Thank you

Writing code without pointer is wrong ?

Code: Select all

Procedure.l MyCreateDirectory()
Protected.l out
Protected.s mydir = GetUserDirectory(#PB_Directory_Desktop)+"test"
out=CreateDirectory_(mydir, #NUL)
If out=0
th_errcode=GetLastError_()
EndIf
ProcedureReturn out
EndProcedure

Procedure.l MyRemoveDirectory()
Protected.l out
Protected.s mydir = GetUserDirectory(#PB_Directory_Desktop)+"test"
out=RemoveDirectory_(mydir)
If out=0
th_errcode=GetLastError_()
EndIf
ProcedureReturn out
EndProcedure

MyCreateDirectory()
Delay (2000)
MyRemoveDirectory()

Re: fileapi.h

Posted: Sat Jul 02, 2022 8:18 pm
by Simo_na
infratec wrote: Sat Jul 02, 2022 7:45 pm

And why not DeleteDirectory() :?:
I'm doing some practice with 'api' :idea:

Re: fileapi.h

Posted: Sat Jul 02, 2022 8:21 pm
by Simo_na
infratec wrote: Sat Jul 02, 2022 7:45 pm The link points to RemoveDirectoryA()

'A' means an ASCII string is required.
and
RemoveDirectoryW() ?

i get error with this

Re: fileapi.h

Posted: Sat Jul 02, 2022 8:57 pm
by mk-soft

Code: Select all

dir.s="X:\MyDir"
r1 = RemoveDirectory_(@dir)
Its automatic compile as ASM

Code: Select all

; r1 = RemoveDirectory_(@dir)
  MOV    rax,qword [v_dir]
  MOV    rcx,rax
  CALL   RemoveDirectoryW
  MOV    qword [v_r1],rax

Re: fileapi.h

Posted: Sat Jul 02, 2022 8:58 pm
by infratec
RemoveDirectory_() automatically uses RemoveDirectoryW_() if you use it in PB.

And you can use the variable without @, because when it is defined as string, the variable itself is a pointer to the string location.
But you can also use @ in front. It is no error and sometimes it makes it more clear what is meant.

This has nothing to do with API.

Code: Select all

Dim a(2)

Debug a()
Debug @a()
Debug @a(0)

; But ...

Debug @a(1)
If I need the address I use @a(0),
So I see always that I want the address of element 0.

Re: fileapi.h

Posted: Sat Jul 02, 2022 9:17 pm
by jacdelad
infratec wrote: Sat Jul 02, 2022 7:45 pm The link points to RemoveDirectoryA()

'A' means an ASCII string is required.

So ...

Code: Select all

*Ascii = Ascii("c:\MyDir")
RemoveDirectoryA_(*Ascii)
FreeMemory(*Ascii)
But the 'A' version is not directly available in PB.
You have to import it.

And why not DeleteDirectory() :?:
I know, that's why I wanted to tell the correct way.

Re: fileapi.h

Posted: Sun Jul 03, 2022 4:16 pm
by Simo_na
thank you all for the help :)