"Resource not valid: must be an absolute path with no references to parent directories" error when iterating through a folder - file-io

I'm new to Rust and the ggez game engine, and I am trying to load in a bunch of images from one folder. I keep getting the same error.
I've tried using the Path type, Strings, full directory to the file, and string literals and nothing seems to work. I've spent about 6 hours of coding on this issue.
This is the code that seems to be the problem:
for number in 0..read_dir("resources/images")?.count() - 1 {
let image_path = format!("{0}/{1}.png", "resources/images", number);
images.push(graphics::Image::new(ctx, image_path)?);
}
I expect all the files to load in. It's that simple.
Here's a git repository of a MCVE.
I've also tried using the DirEntry type:
for (number, item) in fs::read_dir(&images_path)?.enumerate() {
images.push(graphics::Image::new(ctx, item?.path())?);
}
It yields the same error.

Related

Where the statusFiles should be saved?

As mentioned here, I tried to use Status Files with the below code:
install(StatusPages) {
statusFile(HttpStatusCode.NotFound, HttpStatusCode.Unauthorized, filePattern = "#.html")
}
and saved the file as below:
But after running it, I got the standard 404 error, which means the file are not seen, do I need to add some thing, or I'm saving them in wrong place?
It looks like statusFiles() does a resolveResource(path), so it is looking at: src/main/resources/ and in order to make it understand/see the statusFiles folder, which is lying inside the resources folder, the filePattern is required to be tuned little nit to reflect it, so the correct code is:
statusFile(HttpStatusCode.NotFound, HttpStatusCode.Unauthorized, filePattern = "statusFiles/#.html")

Always "requiring unknown module" when reading json file

bit of an RN newb here. I'm trying to read some json data files:
function loadCategories() {
const ids = ['tl1', 'tl2', 'tl3', 'tl4', 'tl5', 'tl6'];
ids.forEach(function(id) {
var contents = require('../Content/top-level/' + id + ".json.js");
...
});
}
But here I always get an error:
Unhandled JS Exception: Requiring unknown module "../Content/top-level/tl1.json.js".If you are sure the module is there, try restarting the packager or running "npm install".
The files exist and my relative path logic should be OK given the project structure:
ProjectDir
Components
ThisComponent.js
Content
top-level
tl1.json.js
tl2.json.js
...
i.e. the above code is running from ThisComponent.js and trying to access tl1.json.js, etc so I would think the relative path of ../Content/top-level/tl1.json.js would work.
I've tried:
Restarting the packager
Referencing ./Content/top-level/tl1.json.js instead
Referencing /Content/top-level/tl1.json.js instead
I'm on RN 0.36.0. Gotta be something obvious…right?
This isn't possible in React Native because of how the packager works. You have to require files with static string path. You can use a switch statement something like this -
switch (id) {
case 'tl1': return require('../Content/top-level/tl1.json');
case 'tl2': return require('../Content/top-level/tl2.json');
...
}
Also why does your json files have .js extension?

WinRT loading ResourceDictionary from string

I need to change ResourceDictionary values based a config that comes from the server.
The way I've gone about this is to have a resource file that I open and read the content into a string, do some replacements on it, then write the string back to a file in the temp folder.
What I need to do now is to load the file into the ResourceDictionary.Source which takes a URI.
If I take StorageFile.Path and use that for the URI, it doesn't work.
var resource = new ResourceDictionary
{
Source = new Uri( storageFile.Path )
};
This give me the error Value does not fall within the expected range..
I have tried
new Uri( "ms-appdata:///temp/" + storageFile.Name )
and that give me the error Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)).
I have tried using the local folder instead, which gives me the same errors.
How can I get this to work?
I'd try loading it using XamlReader.Load().

Why does GetBasicPropertiesAsync() sometimes throw an Exception?

In Windows8, I'm trying to use GetBasicPropertiesAsync() to get the size of a newly created file. Sometimes, but not always (~25% of the time), this call gives an exception of:
"Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))".
The file is created using DotNetZip. I'm adding thousands of files to the archive which takes a few minutes to run:
using (ZipFile zip = new ZipFile())
{
zip.AddFile(...); // for thousands of files
zip.Save(cr.ArchiveName);
}
var storageFile = await subFolder.GetFileAsync(cr.ArchiveName);
// storageFile is valid at this point
var basicProperties = await storageFile.GetBasicPropertiesAsync(); // BOOM!
A few apparently random things seem to decrease the likelihood of the exception:
Deleting an existing copy of cr.ArchiveName before the start of the loop.
Not viewing the directory using File Explorer
Weird, huh? It smells like it might be a bug related to File System Tunneling or maybe it's some internal caching that DotNetZip is performing and holding onto resources (maybe renaming the TEMP file) even after the ZipFile is disposed?
Trying to (unsuccessfully) answer my own question.
At first, I though this was a known issue with DotNetZip holding onto file handles until the next garbage collection. I am using the SL/WP7 port of DotNetZip from http://slsharpziplib.codeplex.com/ which presumably doesn't include the bug fixed by this workitem:
http://dotnetzip.codeplex.com/workitem/12727
But, according to that theory, doing:
GC.Collect();
GC.WaitForPendingFinalizers();
should have provided a work around, which it didn't.
Next I tried using handle, which didn't show any other activity on the failing StorageFile.
So for now, I'm still stumped.

I can't get netbeans to find a txt file I have in the same directory... java.io.FileNotFoundException

I can't make it path specific because once I get this program to work (this is the last thing I have to do) I'm uploading to my university's ilearn website and it has to run on my professors computer with no modifications. I've tried a few different amalgamations of code similar to the following...
File file = new File("DataFile.txt");
Scanner document = new Scanner(new File("DataFile.txt"));
Or...
java.io.File file = new java.io.File("DataFile.txt");
Scanner document = new Scanner(file);
But nothing seems to work. I've got the necessary stuff imported. I've tried moving DataFile around in a few different folders (the src folder, and other random folders in the project's NetBeansProjects folder) I tried creating a folder in the project and putting the file in that folder and trying to use some kind of
documents/DataFile.txt
bit I found online (I named the folder documents).
I've tried renaming the file, saving it in different ways. I'm all out of ideas.
The file is just a list of numbers that are used in generating random data for this program we got assigned for building a gas station simulator. The program runs great when I just use user input from the console. But I can not get netbeans to find that file for the life of me! Help!?!?!?
Try adding the file to build path ..
public void readTextFile (){
try{
Scanner scFile =new Scanner(new File("filename.txt");
while(scFile.hasNext()){
String line =scFile.nextLine();
Scanner details=new Scanner(line).useDelimiter("symbol");
than you can work from there to store integer values use e.g in an array
litterArr(size)=details.nextInt();
Note: size is a variable counting the size/number of info the array has.
}
scFile.close();
{
catch
(FILENOTFOUNDEXCEPION e){
..... *code*
}
Keep file in the same folder as the program,but if it is saved in another folder you need to supply the path indicating the location of the file as part of the file name e.g memAthletics.Lines.LoadFromFile('C:\MyFiles\Athletics.txt');
hope this helps clear the problem up :)