Page 1 of 1

[SOLVED] Curious CreateFile Behavior

Posted: Tue Apr 15, 2025 1:34 am
by Randy Walker
With PB ver 5.40 32 bit,This produces NO results after posting C:\ in the debug window.
With PB ver 6.20 64 bit it gives me nope, Not created.

Code: Select all

Debug GetCurrentDirectory()
Name$ = "junk.jnk"
SetCurrentDirectory("C:\")
Debug GetCurrentDirectory()
If CreateFile(0,Name$,#PB_Ascii)
  CloseFile(0)
Else
  MessageRequester("nope","not created")
EndIf
I must be doing something really stupid. Just wanted to create a zero length file.

Re: Curious CreateFile Behavior

Posted: Tue Apr 15, 2025 1:39 am
by idle
you need the qualified path eg "c:\test.jnk" or

Code: Select all

Global file.s = GetTemporaryDirectory() + "test.jnk"  
   If CreateFile(0,file)  
    debug "created file"
     CloseFile(0)
   EndIf  

Re: Curious CreateFile Behavior

Posted: Tue Apr 15, 2025 1:46 am
by Randy Walker
Just to illustrate that I never knew what I was doing. I found code in my main project that queries the system to find out whether or not the system uses NTFS. I set up a global variable to hold the results, but I searched through the whole program and found out that nowhere in the program do I use that information for anything. Even now I can't imagine what use that might have been for anything.

Re: Curious CreateFile Behavior

Posted: Tue Apr 15, 2025 1:55 am
by Randy Walker
idle wrote: Tue Apr 15, 2025 1:39 am you need the qualified path eg "c:\test.jnk" or

Code: Select all

Global file.s = GetTemporaryDirectory() + "test.jnk"  
   If CreateFile(0,file)  
    debug "created file"
     CloseFile(0)
   EndIf  
I tried it your way and still get nope, not created.

Code: Select all

SetCurrentDirectory("C:\")
Debug GetCurrentDirectory()
Global Name$ = GetCurrentDirectory()+"junk.jnk"
If CreateFile(0,Name$,#PB_Ascii)
  CloseFile(0)
Else
  MessageRequester("nope","not created")
EndIf
Tried it with and without Global, which shouldn't be required anyway -- same results.

Re: Curious CreateFile Behavior

Posted: Tue Apr 15, 2025 2:03 am
by Randy Walker
I'm guessing now something in the system is blocking me from writing to C:\

Re: Curious CreateFile Behavior

Posted: Tue Apr 15, 2025 2:06 am
by idle
you have to have permission to write to the directory. Compile with request admin or write to temp or application data

Re: Curious CreateFile Behavior

Posted: Tue Apr 15, 2025 2:17 am
by Randy Walker
idle wrote: Tue Apr 15, 2025 1:39 am you need the qualified path eg "c:\test.jnk" or
I get it now -- you said "Qualified path", however C:\ is not a qualified path.
So replacing C:\ with Get TemporaryDirectory() Did the trick.
THANKS Idle !!! :D

Re: Curious CreateFile Behavior

Posted: Tue Apr 15, 2025 2:30 am
by idle
Randy Walker wrote: Tue Apr 15, 2025 2:17 am
idle wrote: Tue Apr 15, 2025 1:39 am you need the qualified path eg "c:\test.jnk" or
I get it now -- you said "Qualified path", however C:\ is not a qualified path.
So replacing C:\ with Get TemporaryDirectory() Did the trick.
THANKS Idle !!! :D
since win 7 you needed to raise privileges to write to protected directories, we can do that for programs by compiling them with the compiler option "Request Administrator mode for Vista and above"

Re: Curious CreateFile Behavior

Posted: Tue Apr 15, 2025 6:02 am
by Randy Walker
idle wrote: Tue Apr 15, 2025 2:30 am
Randy Walker wrote: Tue Apr 15, 2025 2:17 am
idle wrote: Tue Apr 15, 2025 1:39 am you need the qualified path eg "c:\test.jnk" or
I get it now -- you said "Qualified path", however C:\ is not a qualified path.
So replacing C:\ with Get TemporaryDirectory() Did the trick.
THANKS Idle !!! :D
since win 7 you needed to raise privileges to write to protected directories, we can do that for programs by compiling them with the compiler option "Request Administrator mode for Vista and above"
Yeah, I didn'tealize drive C root directory was restricted. I knew some folders there were but not C:\ itself.
I did say "I must be doing something really stupid."