[SOLVED] How to go back one folder in path string?

TheFabled

Reputable
May 12, 2021
83
10
4,545
TL;DR at bottom

I want to make a “entertainment hub” on my Windows 11 PC. Consisting of Emulators and such. Everything is divided into subfolders, and I’m making shortcut icons to every single game and demos for easy and clean looking access.

But i want to future proof this so that it will work IF i choose to change the drive letter on the disk it’s currently on, or rename mother folders, or if i give the project to someone, it needs to work without hickups.

Folder structure right now is like this:
F:\Folder1\Folder2\Subfolders (as many as needed, one for each emulator)
F:\Folder1\Folder2\Icons
F:\Folder1\Folder2\Shortcuts

This shortcut folder is where every quick launch icon are located, they point towards the real place of what is to be executed. So one icon is specified to point towards F:\folder1\Folder2\Dreamcast\Games\SoulCalibur

And each shortcut icon has it’s own customized icon that is located in F:\Folder1\Folder2\Icons

The problem with future proofing is that this will only work properly if this is always installed on F: drive and the Folder1 and Folder2 name always stays the same. I am trying to find ways to circumvent this.

One thing i tried was to change the path in the shortcut icon that is located in the F:\folder1\Folder2\shortcuts folder from “F:\Folder1\Folder2\Dreamcast\Games” to “..\Dreamcast\Games”. This method is not allowed it seems. I was hoping it would just go one step back from where it’s executed, and rest would work flawlessly, this would solve my problems.

*But, it would NOT solve the customized Icons, they will disappear on reboot if the icons are not in the exact path i fetched them from.

So since that didn’t work, i thought maybe i could make a direct link to where this is located by simply make a “drive” that points there. For example HUB: which goes directly to F:\Folder1\Folder2\

But in Windows you aren’t allowed to to do this, you can only use Drive letters A-Z.

So i thought, well maybe i can just make a .BAT file with the command “subst Z: F:Folder1\” and let this .BAT file launch with Windows, at least i could make that part easier, but then again just having the entire project to always be on F: would be just as easy.

Then again i tried this and even though i do use Z: the icons still have the path “F:\Folder1\Folder2\”

So. Either i can go one step back in the Icon path, or i have will have to always have this located on F:\ or whatever drive i choose, better pick one far down on the list i guess just in case. Or i will have to make some sort of install script for this project that if i ever choose to move this around, the install script will properly change the path in every shortcut icon and move all the files to where they belong, but i have no programming skills and this sounded very workload heavy.
Anyone has any idea on what i should do?


TL;DR:
Instead of a shortcut icon using full path e.g. "F:Folder1\Folder2\Folder3\" to the file's location.
And since the shortcut is stored in: F:\Folder1\Folder2\Shortcuts
is there some way that the path in the shortcut can go one step beck similar to CD.. command?
So something like this: "..\Folder3\" instead of using full path like "F:\Folder1\Folder2\Folder3\"?
 
Last edited:
Solution
For this Project I'm for now just going to use a simple program called Link Fixer that can bulk change all paths inside every shortcut in a folder in one go. I'm not sure about the icons i chose to add to the shortcuts, but anyways, a good and quick solution that works for now.

And to make things easy. I'll just have it on C drive.

EDIT: Holy crap, this also fixes the icons. Then this issue is truly solved.

EDIT 2: OK i just found out that shortcuts auto-update themselves when you doubleclick them after you've either changed the name of the target directory or moved it to another location. I had no idea this was implemented in windows.

Thanks for your help on this Ralston18
Maybe Path and Environmental Variables.

You define a string for the drive/folder/subfolder path to be used by the shortcuts.

Then incorporate that string definition into the shortcut's or shortcuts' location information.

Later if path needs to change you edit the string definition. Do not change the string name.

To provide a possible starting point:

https://poshcode.gitbook.io/powershell-faq/src/getting-started/environment-variables

https://petri.com/powershell-set-environment-variable/

You can google for more information and ideas as necessary.
 
All folders refer to their "mother" directory as "..". So the command "CD .." will always take you back one level in the folder structure.

Since I don't understand your question, or how and/where you plan your shortcuts to work/interact, that's all I have to contribute with.
 
All folders refer to their "mother" directory as "..". So the command "CD .." will always take you back one level in the folder structure.

Since I don't understand your question, or how and/where you plan your shortcuts to work/interact, that's all I have to contribute with.
I just need to know how to go one level back in the path string inside an icon. The icon tells where the shortcut file is located. But it does so with full path names.

I need to go one folder "up", and then into the proper folder. If i can create a path like this, i never have to worry about renaming mother folders or move all of it to an entirely new drive with a different drive letter.
 
Maybe Path and Environmental Variables.

You define a string for the drive/folder/subfolder path to be used by the shortcuts.

Then incorporate that string definition into the shortcut's or shortcuts' location information.

Later if path needs to change you edit the string definition. Do not change the string name.

To provide a possible starting point:

https://poshcode.gitbook.io/powershell-faq/src/getting-started/environment-variables

https://petri.com/powershell-set-environment-variable/

You can google for more information and ideas as necessary.
I have googled my ass off. And i can't find the solution anywhere. Those ideas i find, doesn't seem to work.

After this i started playing around with creating names as drive letters. Like HappyPlace: That just assigns directly into the proper folder. But this isn't possible, as you can only use drive letters. So then i was thinking about making a .bat file that runs with windows that just assigns a drive letter, for example "subst X: F:\elsewhere\Happyplace" in CMD.

Then i have to create a .BAT file that executes with every windows startup. And if I in the future decide to move this Happyplace folder to another drive or change drive letter, i can use this method. Just that this method doesn't work either, because even if you USE the X: to get to the right folder, the icon will still show the F:\elsewhere\happyplace\ path instead of just X:
 
I need to ensure that I understand the requirement(s).

The summary requirement being that you wish to have the executable files that are now in paths such as:

"F:\Elsewhere\HappyPlace\psx\other subfolders or files
"F:\Elsewhere\HappyPlace\dreamcast\other subfolders or files
"F:\Elsewhere\HappyPlace\commodor64\other subfolders or files

And the initial intent is to move the contents of other subfolders or files up to the applicable psx, dreamcast, commodore64 subfolder level.

With all of the applicable shortcut icons and current paths to those files now currently saved in "F:\Elsewhere\HappyPlace\Shortcuts"

Without needing to manually change individual file pathnames per the Shortcut icon. (My underline.)

And the shortcut icons remaining in "F:\Elsewhere\HappyPlace\Shortcuts"

Is that correct?

If not, then show a couple of examples, including full pathnames to files and within shortcuts to show the process you are attempting to implement.

Two parts:

1) The current full file hierarchy from Drive downward.

2) The planned/required full file hiearchy from Drive downward.

Moving files is fraught with risks. Moves are one thing, Changing the directory (CD) per @Nigel Spike is another. The process in mind will likely require both actions. And then some.....

E.g. Go to some subfolder, copy a file, CD to the next level up, and maybe paste the file, delete the original..... [Not a solution, just an example.]

Key is to fully understand the differences between Part 1 and Part 2 above.

And do not attempt anything without a full and proven backups of the files being moved about.

As for "I just need to know how to go one level back in the path string inside an icon. The icon tells where the shortcut file is located. But it does so with full path names."

Very sure that that will require some hefty work to capture the original path string, parse the string to edit out the intervening subfolder ("one level back") and then save the newly edited path name into the shortcut.

And that edit will include putting strings into the pathname so that if the string is edited (because the files were moved again) then all the shortcut pathnames included that string will reflect that change.

= = = =

"Get-ChildItem -Path "F:\Elsewhere\HappyPlace\WinUAE\Autorun Configurations" -Recurse | %{$_.FullName}

Reference =

https://java2blog.com/powershell-get-full-path-of-file/
 
I need to ensure that I understand the requirement(s).

The summary requirement being that you wish to have the executable files that are now in paths such as:

"F:\Elsewhere\HappyPlace\psx\other subfolders or files
"F:\Elsewhere\HappyPlace\dreamcast\other subfolders or files
"F:\Elsewhere\HappyPlace\commodor64\other subfolders or files

And the initial intent is to move the contents of other subfolders or files up to the applicable psx, dreamcast, commodore64 subfolder level.

With all of the applicable shortcut icons and current paths to those files now currently saved in "F:\Elsewhere\HappyPlace\Shortcuts"

Without needing to manually change individual file pathnames per the Shortcut icon. (My underline.)

And the shortcut icons remaining in "F:\Elsewhere\HappyPlace\Shortcuts"

Is that correct?

If not, then show a couple of examples, including full pathnames to files and within shortcuts to show the process you are attempting to implement.

Two parts:

1) The current full file hierarchy from Drive downward.

2) The planned/required full file hiearchy from Drive downward.

Moving files is fraught with risks. Moves are one thing, Changing the directory (CD) per @Nigel Spike is another. The process in mind will likely require both actions. And then some.....

E.g. Go to some subfolder, copy a file, CD to the next level up, and maybe paste the file, delete the original..... [Not a solution, just an example.]

Key is to fully understand the differences between Part 1 and Part 2 above.

And do not attempt anything without a full and proven backups of the files being moved about.

As for "I just need to know how to go one level back in the path string inside an icon. The icon tells where the shortcut file is located. But it does so with full path names."

Very sure that that will require some hefty work to capture the original path string, parse the string to edit out the intervening subfolder ("one level back") and then save the newly edited path name into the shortcut.

And that edit will include putting strings into the pathname so that if the string is edited (because the files were moved again) then all the shortcut pathnames included that string will reflect that change.

= = = =

"Get-ChildItem -Path "F:\Elsewhere\HappyPlace\WinUAE\Autorun Configurations" -Recurse | %{$_.FullName}

Reference =

https://java2blog.com/powershell-get-full-path-of-file/

Hi thanks for your reply. I edited my OP before you replied, but you seem to not have noticed it (by using the old folder names) i made it more understandable i think now.

I will add:
Right now my folders are:
F:\Folder1\Folder2\Dreamcast
F:\Folder1\Folder2\Amiga
F:\Folder1\Folder2\C64
F:\Folder1\Folder2\PSX
F:\Folder1\Folder2\Dragon32
F:\Folder1\Folder2\Shortcuts
F:\Folder1\Folder2\Icons

Inside those folders are the installed emulators, those will have to be configured from scratch if i ever choose to copy this to another computer, because when i doubleclick an .UAE file (Ultimate Amiga Emulator) for example, Windows needs to know where UAE is located.

Everything regarding any emulator, if it is demos or games or software, are in different folder within the emulator folder it belongs. So everything is already sorted and exactly where it's suppose to be.

But since i want a clean way to execute everything, meaning not opening a partiular emulator and then run games, i choose to make shortcuts of everything and add all those shortcuts in the shortcuts folder. Those shortcut icons will have the "F:\Folder1\Folder2\*Emulator*" Path in them, which will become a problem if the disk drive letter ever changes, from for example F: to E:

In this case, i have to manually open every single shortcut icon and rewrite the new path. And there are hundreds of shortcuts.

But i also discovered another problem that even if i find a way to solve this shortcut path problem. The customized icons will become the next even bigger problem. I didn't notice this until i rebooted my PC.

Since i want this to look clean, i make customized icons for every demo and game to add to those shortcuts. But, if those icons are not exactly where they were when i added them, they will not longer work after reboot, so that's another problem.

Right now, the only way this works is if i always use the same drive letter, then i have no problem what so ever. As long as i never rename the folders.
 
Last edited:
You will need to establish some string variables with regards to the pathnames.

Here is what I was thinking prior to delving into the requirements and file structure:

= = = =

How were the string variables declared?

Use Powershell, not DOS.

What are the results of "Get-Variable" (Run at PS> prompt without quotes and with admin rights)?

What are the results of "$Env😛ath"?

What are the results of "dir env:"

What are the results of

"Get-ChildItem -Path "F:\Elsewhere\HappyPlace\WinUAE\Autorun Configurations" -Recurse | %{$_.FullName}

Reference =

https://java2blog.com/powershell-get-full-path-of-file/

Get a sense of what Powershell can tell you about drives, foldes, subfolders, etc..

= = = =

Here is another hint:

https://petri.com/powershell-set-environment-variable/

Take, for example the path

F:\Folder1\Folder2\Icons

Define that path as a string. Incorporate that string in the shortcut path names.

Then if the drive changes from "F:" to "N:" then edit the string accordingly.

Focus on creating just a simple variable/path

Create a pathname String variable that leads to one particular test file. Ensure that the shortcut works.

Move the test file.

Then edit that pathname String variable to lead to the moved test file's new location.

Test the shortcut again to determine if it finds the file in its' new location. If not, what error(s) are presented....

Start simple and get a sense of how the strings work and how you can implement the strings. Look for other explanations and tutorials as necessary.

Define a string that points to a particular drive and a test folder on that drive. Then edit that string to point at another drive and test folder.

And, as always, remember to do any testing or experimenting on copies of drives/folders/subfolders, and files well away from the original files.
 
You will need to establish some string variables with regards to the pathnames.

Here is what I was thinking prior to delving into the requirements and file structure:

= = = =

How were the string variables declared?

Use Powershell, not DOS.

What are the results of "Get-Variable" (Run at PS> prompt without quotes and with admin rights)?

What are the results of "$Env😛ath"?

What are the results of "dir env:"

What are the results of

"Get-ChildItem -Path "F:\Elsewhere\HappyPlace\WinUAE\Autorun Configurations" -Recurse | %{$_.FullName}

Reference =

https://java2blog.com/powershell-get-full-path-of-file/

Get a sense of what Powershell can tell you about drives, foldes, subfolders, etc..

= = = =

Here is another hint:

https://petri.com/powershell-set-environment-variable/

Take, for example the path

F:\Folder1\Folder2\Icons

Define that path as a string. Incorporate that string in the shortcut path names.

Then if the drive changes from "F:" to "N:" then edit the string accordingly.

Focus on creating just a simple variable/path

Create a pathname String variable that leads to one particular test file. Ensure that the shortcut works.

Move the test file.

Then edit that pathname String variable to lead to the moved test file's new location.

Test the shortcut again to determine if it finds the file in its' new location. If not, what error(s) are presented....

Start simple and get a sense of how the strings work and how you can implement the strings. Look for other explanations and tutorials as necessary.

Define a string that points to a particular drive and a test folder on that drive. Then edit that string to point at another drive and test folder.

And, as always, remember to do any testing or experimenting on copies of drives/folders/subfolders, and files well away from the original files.

Ok thanks.

When i wrote strings it seems i opened pandora's box or something. yeah i didn't really know what to call that path thingy.

I need to look into this, i have actually never done anything about the stuff you just wrote. I need to test things. I feel I'm getting very close to just give this project a Drive letter and never ever change it lol. 😂
 
Just take your time and experiment.

Start simple.

Then if you find something that you believe should be working and is not then post your work accordingly.

Explain what you did and what happened or did not happen as applicable.

Being able to work with strings, do parsing, etc. are very important skills.
 
Yeah thanks.

my life would have been easier if Microsoft just allowed us to go back one path instead of always using full path. And also let us make our own "virtual drives" that stick. For example EMULATORS: that just point directly to where i designate it.

For example. Emulators: is a drive pointed to F:\Folder1\Folder2\Folder3\

So when i type Emulators: for example in CMD, i will be in exactly F:\Folder1\Folder2\Folder3 like it actually was a drive. Oh man this would solve everything. But windows won't let me do such an super easy thing.

Unless there is a third party software that can fix this. And trick windows somehow.

Holy crap.. did i just randomly answer my own question? Can virtual drives be the answer somehow? Or a virtual environment of sorts?
 
For this Project I'm for now just going to use a simple program called Link Fixer that can bulk change all paths inside every shortcut in a folder in one go. I'm not sure about the icons i chose to add to the shortcuts, but anyways, a good and quick solution that works for now.

And to make things easy. I'll just have it on C drive.

EDIT: Holy crap, this also fixes the icons. Then this issue is truly solved.

EDIT 2: OK i just found out that shortcuts auto-update themselves when you doubleclick them after you've either changed the name of the target directory or moved it to another location. I had no idea this was implemented in windows.

Thanks for your help on this Ralston18
 
Last edited:
Solution