[SOLVED] Curious CreateFile Behavior

Just starting out? Need help? Post your questions and find answers here.
Randy Walker
Addict
Addict
Posts: 1060
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

[SOLVED] Curious CreateFile Behavior

Post 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.
Last edited by Randy Walker on Tue Apr 15, 2025 2:17 am, edited 1 time in total.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
idle
Always Here
Always Here
Posts: 5897
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Curious CreateFile Behavior

Post 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  
Randy Walker
Addict
Addict
Posts: 1060
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Curious CreateFile Behavior

Post 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.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1060
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Curious CreateFile Behavior

Post 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.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1060
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Curious CreateFile Behavior

Post by Randy Walker »

I'm guessing now something in the system is blocking me from writing to C:\
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
idle
Always Here
Always Here
Posts: 5897
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Curious CreateFile Behavior

Post by idle »

you have to have permission to write to the directory. Compile with request admin or write to temp or application data
Randy Walker
Addict
Addict
Posts: 1060
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Curious CreateFile Behavior

Post 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
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
idle
Always Here
Always Here
Posts: 5897
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Curious CreateFile Behavior

Post 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"
Randy Walker
Addict
Addict
Posts: 1060
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Curious CreateFile Behavior

Post 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."
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Post Reply