Page 1 of 1

Image not showing due to white space in folder and file name.

Posted: Thu Dec 19, 2024 10:09 pm
by santanu@citytech
I have more than 30 folders and 2000 files which have white spaces in many folders and file names. Now it is not possible to edit all of them.
So I need your help on how I can change the coding to show the all images.

Code: Select all

For ex. catalog/dia da mãe/Borboleta 1.jpg
Here is a twist: When running on a local server, the white spaces are converted to %20 and the images are displayed, but this is not happening on the server.

Please help me.

Re: Image not showing due to white space in folder and file name.

Posted: Thu Dec 19, 2024 10:46 pm
by Cue4cheap
santanu@citytech wrote:
Thu Dec 19, 2024 10:09 pm
I have more than 30 folders and 2000 files which have white spaces in many folders and file names. Now it is not possible to edit all of them.
So I need your help on how I can change the coding to show the all images.

Code: Select all

For ex. catalog/dia da mãe/Borboleta 1.jpg
Here is a twist: When running on a local server, the white spaces are converted to %20 and the images are displayed, but this is not happening on the server.

Please help me.
Why isn't it possible? I you are on a flavor of unix (i.e. Linux) it is pretty simple to remove or replace the space in the file name.
Mike

Re: Image not showing due to white space in folder and file name.

Posted: Fri Dec 20, 2024 3:22 am
by khnaz35
You could do something like

Code: Select all

#!/bin/bash

# Function to replace spaces with %20
replace_spaces() {
    find "$1" -depth -name '* *' | while IFS= read -r f ; do 
        mv -i "$f" "$(dirname "$f")/$(basename "$f"|sed 's/ /%20/g')"
    done
}

# Call the function with the directory path
replace_spaces /path/to/your/directory
Just a idea

Re: Image not showing due to white space in folder and file name.

Posted: Mon Dec 23, 2024 8:40 pm
by noramila
Hello Everyone,
I have a similar problem. Instead of renaming the files, can we fix this in the code? Like, can the spaces in the file names be changed to %20 automatically when showing the images? This would save a lot of time.
Any ideas?

Re: Image not showing due to white space in folder and file name.

Posted: Mon Dec 23, 2024 9:20 pm
by OSWorX
noramila wrote:
Mon Dec 23, 2024 8:40 pm
I have a similar problem.
...
Like, can the spaces in the file names be ...
The best option would be: give the images correct names (titles).
Simply and no further solution is needed.

Don't know why it's so hard NOT to use: spaces, Umlauts, special characters.

Re: Image not showing due to white space in folder and file name.

Posted: Tue Dec 24, 2024 12:45 am
by IP_CAM
Well, it's most likely just too much work, to rename image-names .... :laugh: :drunk: :laugh:

Re: Image not showing due to white space in folder and file name.

Posted: Tue Dec 24, 2024 2:17 am
by khnaz35
IP_CAM wrote:
Tue Dec 24, 2024 12:45 am
Well, it's most likely just too much work, to rename image-names .... :laugh: :drunk: :laugh:
Probably if someone has 1,000 or more images

Re: Image not showing due to white space in folder and file name.

Posted: Tue Dec 24, 2024 4:23 pm
by OSWorX
khnaz35 wrote:
Tue Dec 24, 2024 2:17 am
IP_CAM wrote:
Tue Dec 24, 2024 12:45 am
Well, it's most likely just too much work, to rename image-names .... :laugh: :drunk: :laugh:
Probably if someone has 1,000 or more images
Every system (does no matter if Win* or *nix) has tools to rename unlimited images in a batch mode.
But the most important issue is, that users have to learn what is allowed and what not.

*nix is NOT Win*

Nowadays eveyone without any knowledge whats to have websites and webstores.
And then, for every small issue they want to have tools which should do their work.

Of course they can have millions of images, but every one should be renamed the right way prior uploading to a server.

And the problem here is not to display images with correct names, the images have to be stored already with correct names before using them later!