Pick images of root folder from sub-folder
You can reference the image using relative path:
<img src="../images/logo.png">
__ ______ ________
| | |
| | |___ 3. Get the file named "logo.png"
| |
| |___ 2. Go inside "images/" subdirectory
|
|
|____ 1. Go one level up
Or you can use absolute path: /
means that this is an absolute path on the server, So if your server is at https://example.org/, referencing /images/logo.png
from any page would point to https://example.org/images/logo.png
<img src="/images/logo.png">
|______ ________
| | |
| | |___ 3. Get the file named "logo.png"
| |
| |___ 2. Go inside "images/" subdirectory
|
|
|____ 1. Go to the root folder
ASP - Pick Images of Root Folder into Sub Folder
If you make your <img>
tag a server control by adding runat="server"
you can simply do the following and it will always resolve the url correctly, regardless of where the user controls is referenced:
<img id="image" src='<%=ResolveClientUrl("~/images/abc.jpg")' />
The ResolveClientUrl method will automatically resolve the correct path starting off from the root of the app (~/)
Copy first image file from subfolders into parent and rename
You're mistakenly getting the $image
in your $root
-directory since you are using the get-childitem
without any -Path
parameter. For your purpose you need Foreach
$Fld
(folder) seperately:
$Root = (Get-Item -Path '.\' -Verbose).FullName #'
$Folders = Get-ChildItem -Path $Root -Directory
Foreach($Fld in $Folders)
{
$Image = Get-ChildItem -Path $Fld -Name -Filter *.* | Select-Object -First 1
Copy-Item -Path "$($Fld.FullName)\$Image" -Destination "$Root\$($Fld.Name).jpeg"
}
Read-Host -Prompt "Press Enter to exit"
Here is you code a little shortened:
$Folders = Get-ChildItem -Directory # Without -path you are in the current working directory
Foreach($Fld in $Folders)
{
$Image = Get-ChildItem -Path $Fld -Filter *.* | Select-Object -First 1 # Without the -name you get the whole fileinfo
Copy-Item -Path $Image.FullName -Destination "$PWD\$($Fld.Name)$($Image.Extension)" # $PWD is a systemvariable for the current working directory
}
Read-Host -Prompt "Press Enter to exit"
You could be even bolder as the FullName of the folder contains the path:
Copy-Item -Path $Image.FullName -Destination "$($Fld.FullName)$($Image.Extension)"
Getting images from subfolder and title of folder
This might help you. getDirContents
will return all the folders
with images.
function getDirContents($dir){
$files = scandir($dir);
foreach($files as $key => $value){
$path = realpath($dir.DIRECTORY_SEPARATOR.$value);
if(!is_dir($path)) {
$results[] = $value;
} else if($value != "." && $value != "..") {
$results[$value] = getDirContents($path);
}
}
return $results;
}
I have just provided the iteration of all directories, you need to add your div
structure according to your need.
$directories = getDirContents('sub-directory'); // specify your sub-directory here as a parameter
if (!empty($directories)) {
foreach ($directories as $directory => $images) {
// this will be the parent folder of images
echo $directory;
if (!empty($images)) {
foreach ($images as $image) {
// add img tag here with valid url
echo $image;
}
}
}
}
how to load images from different folders and subfolders in python
os.walk() is what you are looking for.
import os
# traverse root directory, and list directories as dirs and files as files
for root, dirs, files in os.walk("."):
path = root.split(os.sep)
print((len(path) - 1) * '---', os.path.basename(root))
for file in files:
print(len(path) * '---', file)
This code will allow you to parse recursively all folders and subfolders. You get the name of the subfolder(labels in your case) and all files in the file
variable.
The next work for you is then to maybe create a dictionnary (or numpy multi-dimensional array) to store for each label (or subfolder) the features of your image.
Show images from subfolders in tkinter
I've found out what to do in this case:
You have to give the path like this:
./mypackages/cards/heart7.gif
This mounts the cwd as "." and lets me acces all files in the subfolders(actually, there was just a point missing!!!)
Related Topics
How to Give a CSS Class Priority Over an Id
Aligning Decimal Points in HTML
Force Browsers to Load CSS Before Showing the Page
CSS Custom Cursor Doesn't Work in Ff/Chrome
CSS Horizontal Centering of a Fixed Div
How to Set an Image's Width and Height Without Stretching It
Can <Span> Tags Have Any Type of Tags Inside Them
Bootstrap Print CSS Removes Background Color
What Is the Standard Naming Convention for HTML/CSS Ids and Classes
Conditional HTML Attributes Using Razor MVC3
Flex Item Should Align Left, Not Center, When It Wraps
How to Maintain Scroll Position in MVC
HTML Video Player Plays Sound But Not Video
Can You Use CSS to Mirror/Flip Text