Relative path in Lua script failing - lua

So, here's one of those too-simple-to-fail bugs that we all hate.
I have a .lua file that, among other things, tries to load an image via Love's newImageData function (and place it into a button):
back_button = buttonmanager.createButton("back", love.image.newImageData("../Images/BackButton.png"), width-200, height-105)
Love fails to load, throwing this error:
./frame.lua:5: Could not open file ../Images/BackButton.png. Does not exist.
I've gone through the stupid-mistakes process ("well, does it actually exist? Where is the folder?" etc) -- the file exists, is in the Images folder, which is one level up -- I can even say "ls ../Images/BackButton.png" from the directory this script sits in, and it outputs BackButton.png as I'd expect.
Is there some weird relative pathing issue I need to watch out for? I tried changing it to an absolute path and it gave me the same error.

The love.filesystem module restricts access to files in certain locations:
This module provides access to Files in two places, and two places only:
* The root folder of the .love-file. (Alternatively a directory).
* The root folder of the write directory.
Is the ../Images directory outside of your game's folder/archive?

Related

Erlang : exception error: no match of right hand side value {error,enoent} while reading a text file

I am currenly working on an erlang project and stuck in reading the file. I want to read a text file which is in the /src folder where all the erlang and a text file are in the same structure. Then too, I am not being able to read the file despite of specifying file paths. Any help would be appreciated.
start() ->
{ok,DataList} = file:consult("Calls.txt"),
io:format("** Calls to be made **"),
io:fwrite("~w~n",[DataList]).
The data file stores contents like : {john, [jill,joe,bob]}.
Try add folder name to the path or try set full patch to the file:
1> {ok,DataList} = file:consult("src/Calls.txt").
Notes: the error {error,enoent} mean that the file does not exist or you don't have a rights to read/write current file, for this case need set 777 rights or similar.
If you need to use src/call.txt, then this simply means that your IDE (or you) has created a src folder in which the calls.txt file has been placed. At the same time, the IDE is using a path that only includes the top level folder (i.e., the root folder for the IDE project). So src/call.txt must be used in that case. This isn’t a problem with Erlang, or even the IDE. It’s just the way your project is set up.
You can do either of two things. Move the calls.txt file up one level in the IDE file manager, so that it can be referenced as calls.txt, not src/call.txt. You can also just change the path to “calls.txt” before you run it from the command line.
enoent means "Error: No Entry/Entity". It means the file couldn't be found. When I try your code, it works correctly and outputs
[{john,[jill,joe,bob]}]

how to find and deploy the correct files with Bazel's pkg_tar() in Windows?

please take a look at the bin-win target in my repository here:
https://github.com/thinlizzy/bazelexample/blob/master/demo/BUILD#L28
it seems to be properly packing the executable inside a file named bin-win.tar.gz, but I still have some questions:
1- in my machine, the file is being generated at this directory:
C:\Users\John\AppData\Local\Temp_bazel_John\aS4O8v3V\execroot__main__\bazel-out\x64_windows-fastbuild\bin\demo
which makes finding the tar.gz file a cumbersome task.
The question is how can I make my bin-win target to move the file from there to a "better location"? (perhaps defined by an environment variable or a cmd line parameter/flag)
2- how can I include more files with my executable? My actual use case is I want to supply data files and some DLLs together with the executable. Should I use a filegroup() rule and refer its name in the "srcs" attribute as well?
2a- for the DLLs, is there a way to make a filegroup() rule to interpret environment variables? (e.g: the directories of the DLLs)
Thanks!
Look for the bazel-bin and bazel-genfiles directories in your workspace. These are actually junctions (directory symlinks) that Bazel updates after every build. If you bazel build //:demo, you can access its output as bazel-bin\demo.
(a) You can also set TMP and TEMP in your environment to point to e.g. c:\tmp. Bazel will pick those up instead of C:\Users\John\AppData\Local\Temp, so the full path for the output directory (that bazel-bin points to) will be c:\tmp\aS4O8v3V\execroot\__main__\bazel-out\x64_windows-fastbuild\bin.
(b) Or you can pass the --output_user_root startup flag, e.g. bazel--output_user_root=c:\tmp build //:demo. That will have the same effect as (a).
There's currently no way to get rid of the _bazel_John\aS4O8v3V\execroot part of the path.
Yes, I think you need to put those files in pkg_tar.srcs. Whether you use a filegroup() rule is irrelevant; filegroup just lets you group files together, so you can refer to the group by name, which is useful when you need to refer to the same files in multiple rules.
2.a. I don't think so.

Update a relative symlink

Is there a way how to update a relative symbolic link using NSFileManager?
I have a directory structure like this:
data/
foo/
bar/
active -> ./foo
active is a relative symlink to a directory inside the data structure. It needs to be relative so it won't break between individual app launches.
I'm looking for a way how to change the symlink to point to bar. I've tried several approaches:
1) moveItemAtURL:toURL: didn't work, because I didn't find a way how to create a toURL that's relative to the data directory. I tried using NSURL's init(string:relativeToURL:) or constructing it manually ("./bar"), but none of this worked (permission problems, etc.).
2) replaceItemAtURL(_:withItemAtURL:backupItemName:options:resultingItemURL:) I got a "The file “active” doesn’t exist." even though it does exist.
3) createSymbolicLinkAtURL(_:withDestinationURL:) threw a file exists error. D'oh.
I ran out of options. Is there a way how to achieve this?

MATLAB: Set current folder to script's locaton

I have a handful of scripts and data in different folders and I use addpath and relative paths very often. My problem is, this only works if my current folder is where the script that I execute is located. For example, if I execute script A which adds path X and later execute script B which lies in path X, Matlab doesn't automatically change the folder and relative paths specified in script B don't work anymore.
Is there a way to automatically set my current folder to the location of the script I'm executing?
/edit: I should note that I use these scripts on different computers with different drive names, so using absolute paths probably won't help.
Put the following line in the script, it would set the current directory = script directory
cd(fileparts(mfilename('fullpath')))

Relative path of a given file from a service application in Delphi

I have a problem loading a file, as I'm passing a relative path to the function FileExists(Filename: String) and it's returning false, that is, it does not find the file in the directory that I pass.
I have a file named Template.html in the D:\Programming\Delphi\Projects\SendMail directory, and a service written in Delphi whose .EXE is in the D:\Programming\Delphi\Automation directory. I am passing the relative path: .\..\Projects\SendMail\Template.html to FileExists(), but it's returning that the file does not exist.
I think that has something to do with the relative path of a service and the relative path of the application being different. Can anybody help me with this?
As lorenzog said, try specifying the full path.
You can also try to set the currentdir to your likings.
//sets currentdir to your application.exe dir
SetCurrentDir(ExtractFileDir(ParamStr(0)));
You assume that the current directory of the service is the directory the executable is stored in. Call GetCurrentDir to find out the current directory.
My experience has been that services start with a working folder of %SystemRoot%\System32 no matter where the actual executable is located.
The way that I have got around this limitation is to write a registry key during installation of the service (e.g. HKLM\SOFTWARE\MyCompany\MyApp\INSTALL_PATH) that points to what I would like the working folder to be. Then when the service starts, it grabs the data from the registry and uses that value as the base when creating paths to files.

Resources