FileSize says file does not exist

Windows specific forum
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: FileSize says file does not exist

Post by PB »

> What's your case scenario for your project?

I need to launch system apps for the user. Mobility Center was one,
but then I discovered the path used to run it with RunProgram wasn't
working, even though I knew the file existed, but FileSize said it didn't.

Code: Select all

; This FAILS on a 32-bit app running on a 64-bit PC.
RunProgram("C:\Windows\System32\mblctr.exe")
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: FileSize says file does not exist

Post by Thunder93 »

Different ways.. but depends on your needs.

Here's one example of many.

Code: Select all

Global Is64OS.l, EnvirSys32.s = GetEnvironmentVariable("SystemRoot")

CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
  Is64OS = Bool(FileSize(EnvirSys32+"\SysWOW64\"))
CompilerEndIf

If Is64OS : EnvirSys32 + "\SysNative\"
  Else : EnvirSys32 + "\System32\"
EndIf

Debug FileSize(EnvirSys32+"mblctr.exe")
Debug EnvirSys32
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: FileSize says file does not exist

Post by PB »

This...

CompilerIf #PB_Compiler_Processor = #PB_Processor_x86

...is not a solution, because it's NOT runtime. It sets the processor
type ONCE for the exe it creates. So if I compile my exe on a 64-bit
PC and then run it on a 32-bit, then Is64OS will be true on the 32-bit.
That's why we need a runtime command for PureBasic that returns the
processor type. It's been requested before but never added. :(
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: FileSize says file does not exist

Post by Thunder93 »

You can run 64App on 32Bit OS? :?
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: FileSize says file does not exist

Post by ts-soft »

PB wrote:This...

CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
checks only, you are compiling in 32-Bit. This have nothing to do with
the OS! You can remove this, if you compile your source always in 32-Bit.

You can't change the pb compiler at runtime, i hope :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: FileSize says file does not exist

Post by PB »

What I mean is this:

Code: Select all

CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
  MessageRequester("Result","32")
CompilerElse
  MessageRequester("Result","64")
CompilerEndIf
If I compile an exe with this on a 32-bit PC, but then run the
exe on a 64-bit PC, the result will show "32", which is wrong.

No code in the 64-bit block will get executed because the exe
was built on a 32-bit PC due to CompilerIf locking the code.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: FileSize says file does not exist

Post by Thunder93 »

There is a misunderstanding here or something...

If you make 32bit App, this will always check regardless if you on x86 or x64 OS .. to see if you have that \SysWOW64\ directory.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: FileSize says file does not exist

Post by ts-soft »

PB wrote:What I mean is this:

Code: Select all

CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
  MessageRequester("Result","32")
This mean, you are using the 32-Bit Version of purebasic, nothing more.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Fred
Administrator
Administrator
Posts: 18247
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: FileSize says file does not exist

Post by Fred »

We use regular Windows API to check the file size, so I bet it's an OS quirck and we won't fix that as it will probably brings other issues.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: FileSize says file does not exist

Post by PB »

> This mean, you are using the 32-Bit Version of purebasic, nothing more

Yes, which means Thunder93's code example is totally pointless.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: FileSize says file does not exist

Post by Thunder93 »

Its only pointless if one doesn't follow.

If you creating 64bit App, nothing needs to change. You should be calling the 64bit system versions on Windows x64.

If you creating a 32bit App, then you must also check to see if your 32bit App is running on a 64bit Windows.


With my existing code, and if I compile 32bit App. The following line will run the respectful version of the file. If I'm on the 32bit OS, works. If I'm on the 64bit OS, it works.

Code: Select all

RunProgram(EnvirSys32+"mblctr.exe")
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Post Reply