a sortable and extensible naming scheme - data-structures

This is a question about a programming structure but I will use filenames to illustrate it:
I have a list of files:
1.jpg
2.jpg
3.jpg
...
15.jpg
16.jpg
What naming scheme would be the most flexible to allow
1) file sorting
2) adding files between existing
For example using 02.jpg instead of 2.jpg will place it before 16.jpg. This is what I need. But if I want to add 15a.jpg then it will be sorted before 15.jpg.
Are there some ready models for that problem?

Related

WinMerge: How to compare folder names and file names only, recursively?

I currently have two main music folders, one is FLAC, ripped from CD, another is MP3, converted from FLAC. Over the years, my primary MP3 collection (in its own folder) has come from various sources, and has become a mess. I apparently messed up some of the FLAC to MP3 conversions too, and appear to be missing .mp3 files in both MP3 folders.
So, I tried WinMerge to see the differences, but it doesn't appear to be able to compare folder and file names only. It supports recursive folder search, which is nice, but without "names only" filtering, pretty much EVERYTHING looks different when comparing FLAC and MP3 files. I've reviewed comparison options and app preferences and tried looking online, and I've found nothing yet.
Maybe WinMerge isn't the best tool for this, but my attempts with other tools have failed, like with WinDiff. What am I missing, or what should I try?
Open CMD/Shell in each of the folders you want to compare.
Run tree /F . > tree.txt in the CMD, that will export the folder and file structures to a plaintext file named tree.txt under dir (If you wanna compare the folder only, just remove the /F param).
Open WinMerge, compare these plaintext files instead of the concrete directories.
PS:
There will be some differences at the head of files, but it is easy to distinguish.
Make sure you run the command in the exact directory for comparison, if you get the structure of parent/sub folder, the result of comparison will be in complete shambles.
Remember to delete the file after comparing if you don't need it anymore.

Find and copy multiple pictures using powershell

I got a list on excel with picture names I have to find, is it in anyway possible to add the list to powershell and find the pictures and copy them out into one folder?
The list is (about 1000)1310 pictures and there is a total of 44k pictures in aprox a ton of folders. I think maybe it was 500k folders.
Picture of how the image software have made the folder structure
Exact number of files and folders, the last 14k pictures are in another main folder and not relevant for the list
Your question is very broad, and I can only give a very general answer. This is clearly scriptable, but it might take a lot of learning and a lot of effort.
First, you might want to consider what the relationship is between the way pictures are named inthe excel sheet and the way the picture files are named in the folders.
If they follow the same naming rules, that gets one big problem out of the way.
Next, you need to learn how to copy and excel table onto a Csv file.
Then you need to learn how to use Import-csv and feed the stream into a pipeline.
Then you need to process the output of the pipeline to a foreach loop that contains a copy-item cmdlet.
If there is a single master folder that contains all the other folders that contain pictures, then you are in luck. Learn the -path, -recurse, and -include parameters.
Perhaps someone who has already dealt with the same problem can provide you with code. But it may not do what you really want.

Bash - Identify files not referenced by other files

I have a website that runs off an OpenWRT router. I'd like to optimize the site by removing an files that aren't being used. Here is my directory structure...
/www/images
/www/js
/www/styles
/www/otherSubDirectories <--- not really named that
I'm mostly concerned about identifying images that are not used because those take the most space. But it would also be nice to identify style sheets and javascript files that are not being used. So, is there a way I can search /www and all sub directories and files and print a list of files in /www/images, /www/js, and /www/styles that are not referenced by any other files?
When I'm looking for files that contain a specific string I use this:
find . | xargs grep -Hn 'myImage.jpg'
That would tell me all files that reference the image. Maybe some variation of that?
Any help would be appreciated!
EV
Swiss File Knife is very nice tool.
Find out which files are used (referenced) by other files through fuzzy content analysis
Consider using a cross-reference program (for example, lxr) for this problem. (I haven't verified if lxr can do the job, but believe it can.) If an off-the-shelf cross-reference program doesn't work, look for an open source cross-reference program in a language you know, and adapt it.

How to hierarchically (levelize) arrange list of file names with matching pre-fixes (LCS) defining the hierarchy - preferably using shell tools

Source code dirs have meaningful file names.
for example AAAbbbCCddEE.h/.cxx : where AAA, bb CC could refer to abbrev of sub-systems or just a functionality-description like "...Print..." or "...Check..."
as the code-base grows we land up with more than handful files per dir. it becomes daunting just to know what is doing what especially for newer-areas.
in this context a generic tool which would levelize all the file-names by dynamically maximally matching there names and display levels and files would be useful.
what constitutes as a level depends whether a matching pre-fix exists in another file.
so in above example if AAAbbbCCddFF.h/.cxx exists in same dir then both AAAbbbCCddFF and AAAbbbCCEE would belong to same level (depth-4) AAAbbbCCdd and displayed together
looks doable with diff (on filenames itself) and shell tools - any similar-existing references would be useful?
Can you please clarify the directory and file naming conventions you have. Perhaps you can put a real example...
E.g.
CarAndEngineSubsystem/
CarThing1.h
CarThing1.cxx
NavigationSubsystem/
NAV_gizmo1.h
NAV_gizmo1.cxx
RapidNavigationSystem/
NAV_sys_gizmo2.h
NAV_sys_gizmo2.cxx
And just how close would it be to use
find . -type f | sort

Arbitrary sort key in filesystem

I have a pet project where I build a text-to-HTML translator. I keep the content and the converted output in a directory tree, mirroring the structure via the filesystem hierachy. Chapters go into directories and subchapters go into subdirectories. I get the chapter headings from the directory and file names. I want to keep all data in files, no database or so.
Kind of a keep-it-simple approach, no need to deal with meta-data.
All works well, except for the sort order of the directories and files to be included. I need sort of an arbitrary key for sorting directories and files in my application. That would determine the order the content goes into the output.
I have two solutions, both not really good:
1) Prepend directories and files with a sort key (e.g. "01_") and strip that in the output files in order not to pollute the output file names. That works badly for directories since they must keep the key data in order not to break the directory structure. That ends with an ugly "01_Introduction"...
2) put an config file into each directory with information on how to sort the directory content, to be used from my applications. That is error-prone and breaks the keep-it-simple no meta-data approach.
Do you have an idea? What would you do?
If your goal is to effectively avoid metadata, then I'd go with some variation of option 1.
I really do not find 01_Introduction to be ugly., at all.

Resources