fileapi.h

Just starting out? Need help? Post your questions and find answers here.
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

fileapi.h

Post 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.
:|
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: fileapi.h

Post by jacdelad »

Code: Select all

dir.s="C:\MyDir"
Debug RemoveDirectory_(@dir)
What exactly is your problem?
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: fileapi.h

Post 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() :?:
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: fileapi.h

Post 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()
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: fileapi.h

Post by Simo_na »

infratec wrote: Sat Jul 02, 2022 7:45 pm

And why not DeleteDirectory() :?:
I'm doing some practice with 'api' :idea:
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: fileapi.h

Post 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
User avatar
mk-soft
Always Here
Always Here
Posts: 5333
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: fileapi.h

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: fileapi.h

Post 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.
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: fileapi.h

Post 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.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: fileapi.h

Post by Simo_na »

thank you all for the help :)
Post Reply