FileSize says file does not exist

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

FileSize says file does not exist

Post by PB »

Same result when run as limited or with admin rights. :shock:

Code: Select all

Debug FileSize("C:\Windows\System32\mblctr.exe") ; -1
Image
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 »

That file doesn't exists in \SysWoW64. Try with the x64 PB Compiler, it should work okay then. :wink:

Using 32Bit App, to see 64bit system32, use instead

Debug FileSize("C:\Windows\sysnative\mblctr.exe")
Last edited by Thunder93 on Wed Mar 05, 2014 1:24 pm, edited 2 times in total.
ʽʽ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
Little John
Addict
Addict
Posts: 4791
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: FileSize says file does not exist

Post by Little John »

Issue confirmed here on Windows 7 x64 with PB 5.21 LTS x86.
The code works here correctly though with PB 5.21 LTS x64.
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 »

Not a bug really. 8)
ʽʽ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 »

No Bug, only virtualisation :wink:

Code: Select all

Define.s File = "C:\Windows\System32\mblctr.exe"
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
  File = "c:\Windows\Sysnative\mblctr.exe"
CompilerEndIf

Debug FileSize(File)
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 »

> CompilerIf #PB_Compiler_Processor = #PB_Processor_x86

But that produces an exe for only one processor type. Do
I have to compile two versions of my app from now on?

And it's not a good enough solution, anyway, because that's
just ONE file. Does my app have to conditionally compile a
whole folder of Windows files to ensure they look right on
any given PC? It's a horrible way to "fix" the problem. :?

And when my users start saying "what's this SysNative all
about", I then have support issues where I have to explain
that what they see in the "Properties" box isn't true at all.

Ah, damn I hate Windows sometimes. Don't know why I'm
still coding for it. POS operating system.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
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 »

If your 32-Bit program run on a 64-Bit OS, you have to use sysnative dir, it is the same with some registry keys.
The redirection is a windows feature :mrgreen: , not a PB Bug
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 »

As a possible solution, is it safe to just search/replace the
"System32" part of the string with "SysNative" if FileSize()
returns -1, then? Seems a lot simpler and the user won't
know it was done that way to present the correct size.

Like this:

Code: Select all

f$="C:\Windows\System32\mblctr.exe"

s=FileSize(f$)

If s=-1
  s=FileSize(ReplaceString(f$,"\System32\","\SysNative\"))
EndIf

Debug s
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
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 »

Check if the sysnative dir exists, if exist, use it!
On a 32-Bit OS you wouldn't found this dir.
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 »

> Check if the sysnative dir exists, if exist, use it!

Not that simple. It doesn't "exist" on my 64-bit Windows.
Can't view it in Explorer or with the "dir" DOS command.
And yes, I'm viewing all files/folders/nothing hidden/etc.
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 »

It's a pseudo directory for 32App on 64bit OS, using Filesize and determining if the folder exists won't work. Use one of many ways already mentioned on the forums.
PB wrote:> Check if the sysnative dir exists, if exist, use it!

Not that simple. It doesn't "exist" on my 64-bit Windows.
Can't view it in Explorer or with the "dir" DOS command.
And yes, I'm viewing all files/folders/nothing hidden/etc.
ʽʽ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 »

Use a 32-Bit FileManager (Total Commander recommend).
Windows-Explorer is bad for none DAUs :mrgreen:
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
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 »

Filesize() is used heavily in some projects. Having said that, .. speed is important. This extra stage would be undesired.
ʽʽ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 »

> speed is important. This extra stage would be undesired.

I know! That's why it sucks to have to do the check. :(
But if you DON'T check, then you're going to have bugs,
just as I showed in my first post. You can't trust FileSize.
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 »

What's your case scenario for your project? Code be different based on your needs. Is it important for your 32App to see 64bit versions of files?
ʽʽ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