Author Topic: fileExists("path") problem  (Read 2677 times)

eDz0r

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
fileExists("path") problem
« on: December 03, 2011, 03:33:35 pm »
i use this
Code: [Select]
function fileExists(path)
{
try
{
local myfile = file(path, "r");
}
catch(myfile)
{
return 0;
}
return 1;
}
if file exist is no problem... but if isn't it have errors  :'(

Code: [Select]
<03/12/2011 - 14:32:34>
AN ERROR HAS OCCURED [cannot open file]

<03/12/2011 - 14:32:34>
CALLSTACK

<03/12/2011 - 14:32:34> *FUNCTION [fileExists()] Scripts/Main/lc_fd.nut line [90]

<03/12/2011 - 14:32:34> *FUNCTION [onScriptLoad()] Scripts/Main/lc_fd.nut line [45]

<03/12/2011 - 14:32:35>
LOCALS

<03/12/2011 - 14:32:35> [path] "/LU/data/test.txt"

<03/12/2011 - 14:32:35> [this] TABLE

<03/12/2011 - 14:32:35> [this] TABLE

<03/12/2011 - 14:32:35>
AN ERROR HAS OCCURED [cannot open file]

<03/12/2011 - 14:32:35>
CALLSTACK

<03/12/2011 - 14:32:35> *FUNCTION [fileExists()] Scripts/Main/lc_fd.nut line [90]

<03/12/2011 - 14:32:35> *FUNCTION [onScriptLoad()] Scripts/Main/lc_fd.nut line [49]

<03/12/2011 - 14:32:35>
LOCALS

<03/12/2011 - 14:32:35> [path] "/LU/data/test.txt"

<03/12/2011 - 14:32:35> [this] TABLE

<03/12/2011 - 14:32:35> [this] TABLE

Force

  • Developer
  • Full Member
  • *****
  • Posts: 204
  • Karma: +6/-2
    • View Profile
Re: fileExists("path") problem
« Reply #1 on: December 03, 2011, 04:24:51 pm »
Err thats totally the wrong way to go about it :o

Code: [Select]
function file_exists( file_path )
{
local file_handle = file( file_path, "r" );

if ( !file_handle ) return false;

return true;
}
Quote
[Tue - 20:09:35] <&VRocker> CRAP!
[Tue - 20:09:43] <&VRocker> i think i just followed through...
Quote
[Sat - 22:11:56] <~Smapy> [R3V]breSt12 killed [R3V]Jack_Bauer. (Splat)

eDz0r

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: fileExists("path") problem
« Reply #2 on: December 03, 2011, 05:50:14 pm »
Err thats totally the wrong way to go about it :o
is not my code... and i'm not very advanced in scripting...

eDz0r

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: fileExists("path") problem
« Reply #3 on: December 03, 2011, 07:12:28 pm »
still not working  :'(
Code: [Select]
AN ERROR HAS OCCURED [getVarInfo: Could not retrieve UserData]

<03/12/2011 - 18:10:32>
CALLSTACK

<03/12/2011 - 18:10:32> *FUNCTION [onScriptLoad()] Scripts/Main/lc_fd.nut line [45]

<03/12/2011 - 18:10:32>
LOCALS

<03/12/2011 - 18:10:32> [this] TABLE

Force

  • Developer
  • Full Member
  • *****
  • Posts: 204
  • Karma: +6/-2
    • View Profile
Re: fileExists("path") problem
« Reply #4 on: December 03, 2011, 07:28:57 pm »
Whats line function onScriptLoad look like?
Quote
[Tue - 20:09:35] <&VRocker> CRAP!
[Tue - 20:09:43] <&VRocker> i think i just followed through...
Quote
[Sat - 22:11:56] <~Smapy> [R3V]breSt12 killed [R3V]Jack_Bauer. (Splat)

eDz0r

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: fileExists("path") problem
« Reply #5 on: December 03, 2011, 07:33:59 pm »
The errors (if the file not exist)
Code: [Select]
<03/12/2011 - 19:04:17>
AN ERROR HAS OCCURED [cannot open file]

<03/12/2011 - 19:04:17>
CALLSTACK

<03/12/2011 - 19:04:17> *FUNCTION [file_exists()] Scripts/Main/new.nut line [18]

<03/12/2011 - 19:04:17> *FUNCTION [onScriptLoad()] Scripts/Main/new.nut line [3]

<03/12/2011 - 19:04:17>
LOCALS

<03/12/2011 - 19:04:17> [file_path] "/Text.txt"

<03/12/2011 - 19:04:17> [this] TABLE

<03/12/2011 - 19:04:17> [this] TABLE



The code:
Code: [Select]
function onScriptLoad()
{
if(file_exists("/Text.txt"))
{
print("Yeap");
}
else if(!file_exists("/Text.txt"))
{
print("Nope");
}
return 1;
}

function file_exists(file_path)
{
local file_handle = file(file_path, "r");

if(!file_handle)
{
return false;
}
return true;
}
« Last Edit: December 03, 2011, 08:07:31 pm by eDz0r »

eDz0r

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: fileExists("path") problem
« Reply #6 on: December 07, 2011, 05:23:31 pm »
BUMP

VRocker

  • Liberty Unleashed Developer
  • Administrator
  • Full Member
  • ******
  • Posts: 342
  • Karma: +43/-15
    • View Profile
    • Madnight Software
Re: fileExists("path") problem
« Reply #7 on: December 07, 2011, 05:30:56 pm »
Tried not using / as the first character? E.G. Test.txt instead of /Test.txt

The file operations have some protection in to stop you writing all over the hdd so it could be stopping you from doing this, since on linux you'd be writing to the root of the drive


stormeus

  • No-Lifer
  • Developer
  • Full Member
  • *****
  • Posts: 112
  • Karma: +13/-2
    • View Profile
Re: fileExists("path") problem
« Reply #8 on: December 07, 2011, 08:53:24 pm »
The code with try { }, though completely bad practice, would have worked and might be the only way of doing it since file() throws exceptions instead of null handles.
Quote
Morphine says:
    them LU devs ranting about how LU doesn't have client pickups
    while us VC:MPers don't have client anything
    ;_;

Stormeus Argo says:
    we have client crashes though
    ohohohohoho

Morphine says:
    LU DOESN'T HAVE THAT

Stormeus Argo says:
    LU - 0
    VC:MP - 1

eDz0r

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: fileExists("path") problem
« Reply #9 on: December 09, 2011, 05:09:42 pm »
Tried not using / as the first character? E.G. Test.txt instead of /Test.txt

The file operations have some protection in to stop you writing all over the hdd so it could be stopping you from doing this, since on linux you'd be writing to the root of the drive
tried...

VetalYA

  • Guest
Re: fileExists("path") problem
« Reply #10 on: January 21, 2012, 11:28:47 am »
This problem should have some solution, even if it will be an a "idiotic" solution...For example  with timers & global vars, Lol

This Should work.

 

© Liberty Unleashed Team.