How do I see how many items are in a website directory? - file

I am making a package manager in Rust, and I want a way to see how many files are being stored in a specific website directory. For example, how many files are in this folder: https//codeberg.org/Oglo12/upkg-standard-repo/raw/branch/main
Basically, what fs::read_dir() does, but for websites.

Related

VB.NET Copying Database template files to selected folder location during installation

net project as well as a setup project. I also have it so that during installation it asks the users to enter a file location to store their database. the plan is to have an empty .mdf file, with all the tables setup, copied into that folder and I store the folder path in a config file.
this is mainly because I am planning on having multiple separate applications that all need the ability to access the same database. I have it storing the folder path in my config file the only thing I'm having trouble with is
storing the template files I don't know if i should do this in the setup project or main project
how to copy said template files into a new folder
so far I have been unable to find a solution so any help is appreciated
Well here is what I do this in a few of my projects - something that has proven reliable enough for me over the years (which you may or may want to do as well):
I have the program itself create the database files in an initialization routine. First however, it creates the sub folders in which the database files will be stored, if they don't already exist.
To do this, the program just checks if the folder exists and if the database file exists and if they do not, it creates them on the spot:
If Directory.Exists(gSQLDatabasePathName) Then
Else
Directory.CreateDirectory(gSQLDatabasePathName)
End If
If File.Exists(gSQLiteFullDatabaseName) Then
Else
...
I also have the program do some other stuff in the initialization routine, like creating an encryption key to be used when storing / retrieving the data - but that may be more than you need (also, for full disclosure, this has some rare issues that I haven't been able to pin down).
Here too are some addition considerations:
I appreciate you have said that you want to give the user the choice of where to store their database files. However, I would suggest storing them in the standard locations
Where is the correct place to store my application specific data?
and only allowing the users to move them if the really need to (for example if the database needs to be shared over the network) as it will make the support of your app harder if every user has their data stored in different places.
I have found letting the user see in their options/settings windows where their database is stored is a good idea.
Also to encourage them to back those files /directories up.
Also to create automatic backups of several generations for the user.
Hope this helps.

Reading data organised in folders with Codename one

I've got data generated by a desktop application. These data are organized in a 2-levels folders system : each folder is a physical representation of one object, with an image file, a property file and different text files. There is no way I can change this structure.
I'm willing to show these data with a mobile application. I started something with Intel XDK, but I feel more comfortable with java. So I'm building a POC with Codename One. The final goal is to get these data on the mobile device with a DropBox integration. But for now (in dev phase), I'm going to manually download the data in a user folder on the device.
In netbeans, I put a sample of these data in the src/ folder, but when I try to read them, I've got an error telling me that nested directories are not allowed:
ERROR: resources cannont be nested in directories in Codename One! Invalid resource: /00002/page.properties
Any suggestion on how I can move on with the development, using with static folders ?
Resource files must be placed in the root of the src directory to be packaged and can't be deeper. The reasoning is that we don't generate a JAR but rather a native package where hierarchies are pretty different.
If you need this exact structure just extract them into the FileSystemStorage on the first activation then you can use the hierarchy that's available there.

What is the recommended way to package many photos in Codename One?

I'm developing an app that'll show a catalog of hundreds of products, each with a photo. In thinking how to deploy those images in Codename One, I found two options:
1) I can insert them in the resources file and fetch them with fetchResourceFile().getImage(). The downside is that, because they're so many, and because there's no folder system in the resources file gui, it'll make it hard to find icons and other images in the mix.
2) Copy them to the root folder and fetch them with Image.createImage(). I find this preferable because I can leverage the OS's applications to find/replace/rename them directly; but like before, it'll mix them up with other files that share the same requirement, like the resources file, xml files and others.
My question is, is there a better way of packaging them in a way that will keep them separate from other resources and keep things organized?
You can't rename or change anything about images that you place in the SRC directory since they will be packaged in the jar or .app bundle both of which are unmodifiable. There is a platform dependent size limit for bundles so if your app grows too much it just won't install in the various OS's.
The best way is to include a subset of the images in the resource file and then as the app is launched start downloading the rest in the background to avoid a big application overhead.

Dart: Accessing a resource out side the project|web/ directory

I have a web-app(browser based) which needs to access a folder full of icons that resides outside the web folder.
This folder MUST be outside the web folder, and would ideally exist outside the project folder all together
however, when specifying the path to the folder neither "../" or making use of a symlink will work
when the page attempts to load the image I always get
"[web] GET /Project|web/icons/img.png => Could not find asset Project|web/icons/img.png."
however I set the image source to "../icons/img.png"
how can i get dart to access this file properly
PS: I attempted a symlink to another part of the filesystem (where the images would be kept ideally) however this did not work either.
The web server integrated into DartEditor or pub serve only serves directories that are added as folders to the files view. When you add the folder to DartEditor you should be able to access the files. This is just for development.
You have also to find a solution for when you deploy your server app. It would be a hazardous security issue when you could access files outside the project directory. Where should the server draw the line? If this would be possible your entire server would be accessible to the world.
Like #Robert asked, I also have a hard time imaging why the files must not be in the project folder.
If you want to reuse the icons/images between different projects you could create a resource package that contains only those images and add them as a dependency to your project.
If you want a better answer you need to provide more information about your requirements.
If you wrote your own server (by using the HttpServer class) it may be possible to use the VirtualDirectory to server your external files.
Looking at look the dartiverse_search example may give you some ideas.
You could put them in the lib directory and refer to them via /packages/Project/...
Or in another package, in which case they would be in a different place in the file system. But as other people have said, your requirement seems odd.

Share resources among multiple CakePHP webroots on Windows / IIS?

I've got a CakePHP install running six different web sites, each with their own webroot. All of the base code is the same (controllers, models, etc.), just the css, images, js and so forth are split into the separate webroots (app/webroot, app/webroot_second_site, app/webroot_third_site, etc.)
My question is: Is there a way to share common resources among the webroots? So we don't have six different copies of TinyMCE and jQuery cluttering up our project, and more importantly to me, so that we can make a change in a common CSS file instead of having to copy/paste a change across six different sites' folders?
If these sites were running on a Linux box, I think it could be fairly easily accomplished with a symlink from each of the webroots to a common folder higher up in the directory tree, but we're running Windows Server 2003 / IIS 6. Any suggestions?
Turns out you can do directory symlinks in NTFS file systems. Or at least close enough for practical purposes. "NTFS Junctions" will work for what you want.
Grab the Sysinternals "Junction" program for a simple command-line program to create/delete these junctions.
Then you can link whatever common directories you need to a single master directory.
For example, if you have
webroot1/
webroot2/
webroot3/
each with their own "js/" directory, then you could create
webroot_common/js/
and then symlink... er, "create junctions" to that new directory like so:
junction webroot1/js/common webroot_common/js
junction webroot2/js/common webroot_common/js
junction webroot3/js/common webroot_common/js
(yes, the "junction" program takes its inputs backwards from Linux "ln -s")
Then you can put whatever common js files you need, like jQuery, in that common folder, and leave any site-specific js files in "webrootX/js".
You could make a static server. Add a DNS entry to something like static.yoursite.com. Link to those files from your other sites -- probably you could just modify the HTML helper so that it will automatically create links to the other domain.
This can help with performance, because you can run something like nginx to serve these static files. It will also parallelize the resource retrievals -- most browsers will allow 2 connections to a given server, so the static stuff competes with those connection resources that are needed by the dynamic stuff. In essence, the user will start 2 connections to your dynamic stuff as well as 2 connections to the static resources.
Works pretty well IME.
This will work. You will need to redefine the directories for a windows server, but you will understand it well enough.
First, put your APP and CAKE directories a level above the public_html.
/var/www/app
/var/www/cake
Make sure that the folder cake has all of the cake folders in it (cake, vendors, etc.)
Point your sites to their public_html directories.
/var/www/html/site1
/var/www/html/site2
The webroot content will sit in each of the public_html directories. Now, modify your index.php file in each of the webroots to point to the same app:
if (!defined('ROOT')) {
define('ROOT', DS.'var'.DS.'www'.DS.'app');
}
if (!defined('APP_DIR')) {
define('APP_DIR',dirname('app'));
}
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH', DS.'var'.DS.'www'.DS.'cake');
}
Make sure that rewrite is turned on of course. Then it will all run off the same code but use the webroot where the index.php is being served from.

Resources