Note,
this is quite advanced, hopefully
I've got things correct, but
let
me know if not. If you're a
paid-up supporter of
Neocities (I'm not) then you have
other options at your disposal, such
as FTP access.
Please keep
backups of your website and
files and do your own research;
I have done my best to provide
accurate information here but
this page deals with the
deleting of files, and so there
is a risk that something could
go wrong or a mistake is made
and files lost. |
Anyway,
when I overhaul a particular section
of my website (offline) I might opt
to just delete the online directory
and re-create it and re-upload the
contents afresh. This is partly
because the Neocities web interface
doesn't provide an easy way to
delete a list of files; you have to
delete them one by one (and after
each one you're returned to the top
of the page...), and that's
not ideal if there are a lot of
files.

Some
check boxes would be nice...
But what
if we're dealing with the root
directory? (you can't delete that)
Tip,
Keep the bulk of
your files in sub directories to
avoid this issue in the first
place!
|
I
encountered just this issue as I'd
accumulated a lot of image files in
my website's root directory. Because
I work on my website offline I could
move them easily to new directories
and re-upload them there, but then I
needed to delete the ones from root
online.
Here
is how I achieved this (with the
help of ChatGPT):
You need
'The
Neocities CLI', but first 'Ruby':
To
install from my Linux OS I did:
sudo
apt-get install ruby-full
Then:
sudo gem install neocities
Then:
neocities login
As a
test here you can do: neocities list
|
|
 |
Found
this
page helpful?
 |
|
|
Now for
the complicated part (which took
some back and forth with ChatGPT):
neocities list / | sed
's/\x1b\[[0-9;]*m//g' | grep -iE
'\.(jpg|png|gif)$' > image_files.txt
cat image_files.txt |
while read file; do neocities delete
"$file"; done
You
should see it working through the
list, which can take a while if you
have a lot. I had a few image files
left over for some reason but this
was no trouble to deal with manually.
Explanation:
A reason
this command is so complicated is
because the wildcard option (neocities
delete *.jpg *.png *.gif) didn't
work.
Essentially what the solution above
does is produce a list of all of the
image files (jpg png and gif*) in
your root directory and saves that
to a file (image_files.txt which in
my case is put in my home
directory). It does some filtering
to remove some erroneous stuff so
the list is clean and then the
next command is to remove those
listed image files.
Here's how ChatGPT explained it:
neocities list /
lists all files in the root
directory, including color codes.
sed
removes any color formatting (ANSI
escape codes).
grep
filters only the image files (with
extensions
.jpg ,
.png ,
.gif ).
-
The list of image filenames is
then saved to
image_files.txt
for easy access.
cat
image_files.txt
outputs the list of image
filenames.
-
Each filename is read one at a
time by the
while
read file
loop.
-
For each filename, the
neocities
delete "$file"
command is executed, which deletes
the file from your site.
-
This process repeats for each
filename listed in
image_files.txt .
*If you have .jpeg
and/or .webp extensions you will
need to add these also to the
command (I tend to avoid these).
Tip,
Keep your filenames
simple, such as all lowercase
and use common extensions rather
than, for example, a mix of .jpg
and .jpeg.
|
Because there were some image files
I wanted to keep I needed to go back
into Neocities and re-upload them,
but that was simple enough.
Click
here to read about "How I organise my
website behind the scenes"
|