[RESOLVED] Switching from absolute to relative file refs

"Please leave a message at the beep, we will get back to you when your support contract expires."

Moderators: phlip, Moderators General, Prelates

User avatar
SpringLoaded12
Posts: 350
Joined: Wed Oct 08, 2008 1:58 am UTC
Location: Guarding the Super Missile
Contact:

[RESOLVED] Switching from absolute to relative file refs

Postby SpringLoaded12 » Sat Feb 20, 2016 4:15 pm UTC

Hate to be that guy that only ever shows up to ask for help, but I know no better place for these sorts of questions.

A long time ago it was bugging me that my music playlist files wouldn't function if I moved the music library to a new area, even though the playlist file was right there in the library and all the subfolders were the same. I knew this could be fixed if the playlists could be made to use relative file references instead of absolute ones (i.e. if the music file and the playlist file are in the same folder, instead of listing the complete file path, it would just list the filename and the system would search the current folder; and if the music file was in a subfolder of the folder where the playlist file was, the file path would only contain that subfolder and the music filename). I found a nifty little program that would easily do this for me called listFix(), which you can find easily if you have a similar hankering.

Now, I'm having the same problem, but not with music playlists -- it's happening in other areas. The one that's got my attention at the moment is file folder properties. I have a few dozen folders all with custom icons, but they're on an external drive and the file path for the icons is absolute, so they only work on a new machine if it just happens to assign the same drive letter to this external as it had on the machine where I originally set up the folder icons.

There are two possible solutions, but I'd prefer the first if anyone knows how:
1. A way to assign folder icons with relative file references (super ultra uber bonus points if there's a way to do this in ALL situations instead of just folder properties). A way to do it quickly & easily is of course preferred, but if it comes down to doing things barebones or editing a file in Notepad that maybe wasn't meant to be edited that way, I'm willing to do that.
2. A way to manually select drive letters for external drives on a Windows machine, which would be a hotfix for this specific case.
Last edited by SpringLoaded12 on Sat Feb 27, 2016 1:10 am UTC, edited 1 time in total.
"It's easy to forget what a sin is in the middle of a battlefield." "Opposite over hypotenuse, dipshit."

User avatar
Flumble
Yes Man
Posts: 1835
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Switching from absolute to relative file references

Postby Flumble » Sat Feb 20, 2016 10:32 pm UTC

Well, most folder icons I know of are configured with a hidden file (only visible when you show protected system files) within that folder called desktop.ini. For example, an older version of Visio crates this desktop.ini for one folder:

Code: Select all

[.ShellClassInfo]
InfoTip=Contains shapes for use in Visio.
IconFile=_private\folder.ico
IconIndex=0

[edit]
Actually, when you set them yourself, the icon is filed under another key:

Code: Select all

[.ShellClassInfo]
IconResource=C:\Windows\system32\SHELL32.dll,12
[/edit]

So, yes, you can have relative paths for the icon.
And you can make them all relative by replacing the pattern /(IconResource|IconFile)=(common absolute path)(.*)/ in all desktop.ini files on your drive. (assuming you have a tool that can handle text replacement in many files, e.g. notepad++)

Note that linux, on average, is a bit more used to relative paths. And when it isn't, you can easily set up mount points and hard links anywhere you want.

User avatar
SpringLoaded12
Posts: 350
Joined: Wed Oct 08, 2008 1:58 am UTC
Location: Guarding the Super Missile
Contact:

Re: Switching from absolute to relative file references

Postby SpringLoaded12 » Sun Feb 21, 2016 7:46 pm UTC

Flumble wrote:And you can make them all relative by replacing the pattern /(IconResource|IconFile)=(common absolute path)(.*)/ in all desktop.ini files on your drive. (assuming you have a tool that can handle text replacement in many files, e.g. notepad++)

I use Notepad++ a lot, but never knew it could do that. I'll see if I can find a tutorial/some documentation on that feature.

Thanks for the info. Kind of funny that relative file paths are completely valid in Windows, but it still defaults to absolute ones and offers no option to choose without editing system files.
"It's easy to forget what a sin is in the middle of a battlefield." "Opposite over hypotenuse, dipshit."

User avatar
SpringLoaded12
Posts: 350
Joined: Wed Oct 08, 2008 1:58 am UTC
Location: Guarding the Super Missile
Contact:

Re: [RESOLVED] Switching from absolute to relative file refs

Postby SpringLoaded12 » Sat Feb 27, 2016 1:19 am UTC

Well, it's been a few days without any updates on this, but I figured I should update it with some closure for the next person who comes along. Wouldn't want to be that guy.

I fired up Notepad++ and set down to editing those desktop.ini files one at a time. Easy enough to do, but there were 26 of these, and by the 4th one I was getting annoyed knowing that there was a faster way; if only I knew how. Decided to take a swing at that Notepad++ idea. Lo and behold, I see Find in Files. Problem is, I put each icon into the folder that utilizes it, so all these icon file paths initially have a common absolute path that can be removed, but they also have one more folder in the path that needs to go, and those are all different. Seemed like no quick-fixes were in sight given that no matter what I do, I would have to remove those folder names one by one.

But then I saw the little regular expressions checkbox in Notepad++'s Find window, looked up a crash course of regex online, and figured out how to format the statement within 5 minutes. Mission accomplished. The result:

Image

22 files edited in 1 shot, and it worked perfectly.
This completely blew my mind, and now I have a new trick up my sleeve for the future.

Thanks again for the advice, Flumble!
"It's easy to forget what a sin is in the middle of a battlefield." "Opposite over hypotenuse, dipshit."


Return to “The Help Desk”

Who is online

Users browsing this forum: No registered users and 4 guests