0

I'm trying to run a simple cd Foldername in command prompt for a folder on my desktop and it says The system cannot find the specified path. I'm losing my mind.

The same command works on my laptop, but not on the PC. I've troubleshooted everything I can think of. Environment variable paths are all okay, cd Desktop command works. Tried running the command in Powershell and get the same error.

I'm pulling my hair out.

The folder also doesn't show when i run dir.

I'm at a loss.

Can anyone help please?

Note: also troubleshooted cmd restrictions in gpedit, regedit and ran as admin

samthecodingman
  • 10,588
  • 2
  • 15
  • 36
ZeNightman
  • 19
  • 1
  • 4
  • Out of curiosity what is the name of the folder you are trying to access? – samthecodingman Aug 10 '19 at 12:53
  • CProjects. I've tried changing it to numbers only, tried literally everything. – ZeNightman Aug 10 '19 at 13:22
  • 1
    I've also tried chdir /d "C:\Users\User\Desktop\CProjects". Nothing. And on the laptop works perfectly fine. – ZeNightman Aug 10 '19 at 13:23
  • Is CProjects a folder on the desktop? If so, does using `cd %USERPROFILE%\Desktop\CProjects` work? – samthecodingman Aug 10 '19 at 13:24
  • Tried that too but to no avail. Practically I'm trying to follow a tutorial on C++ (wanna get back into coding after a 6 year hiatus), and I've created the folder as per the guys instructions. I've also added C:\MinGW\bin as a path in Environment Variables, but to simulate it on the laptop i've also added it there and it still works, so that's not what's causing it. Created the folder, in the folder there's another folder titled project1, and in project1 a basic CPP file with 3 lines of code. – ZeNightman Aug 10 '19 at 13:29
  • Ok. Let's try the cop-out method then, open the folder (in Explorer), then whilst holding down `Shift`, right-click the background of the folder and click "Open command window here". – samthecodingman Aug 10 '19 at 13:31
  • It gives me the option of Opening a Powershell window though. – ZeNightman Aug 10 '19 at 13:37
  • 1
    I've managed to add the Open command window here through a registry update. What concerns me is that when i run dir in Project1 directory, it doesn't show the main.cpp file. It actually says 0 files. L.E. Sorted, kinda. Thank you so much mate. You're a star. Can't figure out why it won't access the directory through chdir or cd command tho, unless opened as stated by you. – ZeNightman Aug 10 '19 at 13:39
  • Ah yes, I forgot that Powershell is the new default - been a while since I've manually setup a system without firing off all my customization scripts. My current theory is that you may have OneDrive configured to backup your files which includes your desktop, which means the script folder isn't actually `%USERPROFILE%\Desktop\CProject` but instead `%USERPROFILE%\OneDrive\Desktop\CProject` or similar – samthecodingman Aug 10 '19 at 13:51
  • But wouldn't that mean that cd C:\Users\User\Desktop won't work? – ZeNightman Aug 10 '19 at 14:32
  • 1
    Just tried with OneDrive, and it worked. I hate windows. – ZeNightman Aug 10 '19 at 14:33
  • Not necessarily. Because the system default desktop folder (`%USERPROFILE%\Desktop`) is expected to exist for a lot of programs, it would be left untouched. I actually have my desktop on a different drive and have created a directory junction (symlink) to point it at the right spot. Maybe you can do the same to point `%USERPROFILE%\Desktop` to `%USERPROFILE%\OneDrive\Desktop` save yourself some trouble in the future. I'll compile our convo into an answer now. – samthecodingman Aug 10 '19 at 14:39
  • I've noticed something really odd. When I opened CMD the path was C:\Users\User> by default. Typed it cd Desktop, all good so far. And this is why i couldn't figure it out what's wrong, since the path C:\Users\User\Desktop is recognized by CMD, while C:\Users\User\Desktop\CProjects isn't. – ZeNightman Aug 10 '19 at 14:47
  • That's what tipped me off to that your desktop isn't where you thought it was and why I recommended the shift-right-click approach. It was going to allow you to get to work while I sniffed out what could be the cause without you knowing. I used to have a multi-desktop software called [DexPot](https://dexpot.de) (now redundant due to new Windows features) installed on my PC that switched my system default Desktop folder depending on my workspace. I then remembered OneDrive being pesky about backing up my docs and desktop which led to finding the culprit. – samthecodingman Aug 10 '19 at 14:54
  • Possible duplicate of [Difference between `./` and `~/`](https://stackoverflow.com/a/55342466/874188) – tripleee May 23 '21 at 08:07

2 Answers2

2

Note: This answer was discovered through conversation in the question's comments.

The location of the Desktop folder in most versions of Windows is %USERPROFILE%\Desktop, which for most users becomes C:\Users\YOURUSERNAME\Desktop.

However, this location can also be changed by programs installed on your computer and is a common feature amongst workspace-switching/multi-desktop utilities.

In later editions of Windows in particular, OneDrive is installed as part of the operating system and as part of initial setup, it will ask you if you wish to backup your documents, pictures and desktop to your OneDrive account. This will allow you to have the same files available on each Windows computer you use that where you log into OneDrive.

If you choose to backup your Desktop with OneDrive, your desktop will silently be moved to %USERPROFILE%\OneDrive\Desktop instead of the default. The %USERPROFILE%\Desktop will still exist in it's original location, but will no longer contain your desktop files.

Because the original Desktop folder exists, using cd Desktop after opening command prompt will still work, but as it contains no files or folders, using cd SomeFolderOnTheDesktop will lead to the The system cannot find the specified path error.

The Solutions

1. "Open command window here"

In older versions of Windows, you can open any folder in Explorer, hold down the Shift key, right-click the background of the open folder and then select "Open command window here". Since Windows 10, this has been replaced with "Open Powershell window here". However you can bring back "Open command window here" manually by following this WindowsCentral guide.

2. Use a directory junction to link your the system Desktop folder to the OneDrive Desktop folder.

Open the Run dialog (Windows Key + R), then type in %USERPROFILE% and press Enter. This will open your User Profile directory (C:\Users\YOURUSERNAME). Rename the existing Desktop folder to something like "Desktop-old". Then go into the OneDrive folder, right-click the Desktop folder there, and then select "Always keep on this device". If your internet goes out, your Desktop files will still be available and not cause future head-scratching when you can't open them or they take a long time to open.

Open the Command Prompt, and then execute the following command:

mklink /J "%USERPROFILE%\Desktop" "%USERPROFILE%\OneDrive\Desktop"

Now whenever you open %USERPROFILE%\Desktop (in any program) you'll actually be looking at the contents of %USERPROFILE%\OneDrive\Desktop. So cd Desktop and then cd SomeFolderOnTheDesktop will work as expected.

Disclaimer: Care must be taken when working with files in %USERPROFILE%\Desktop with this method, as there may be unintended bugs with OneDrive's sync features. I haven't had any issues, but the warning is there none-the-less.

3. Disable OneDrive's Desktop backup

Note: Backups are a good idea. Avoid if possible.

Right-click the OneDrive icon in the system tray and select Settings. In the new window, change to the "Back up" tab, and then click "Manage backup". Work through the setup wizard to reconfigure your settings.

samthecodingman
  • 10,588
  • 2
  • 15
  • 36
-1

I had the same issue. I was trying to open and run a python program on my computer and was getting "The system cannot find the path specified." So I thought about it, what if I follow the path on my C: drive manually and see if what I am looking for is there. On my actual, visible, desk top the file I was trying to load was there. Do this:

Open C: drive in File Explorer.

Double click Users

Double click user name folder. For instance, my last name is Sanders but my user file name is "sande".

Scroll and look for Desktop. Double click and open it.

The file you are trying to access should be in this folder. This is the pathway you are telling your computer to take in the Command Prompt. If the folder isn't there:

Go to where you know the folder is, ie your actual desktop. Copy the file and paste it into the empty desktop folder. Boom! Your in!

I hope this helps someone with the same issue. I was frustrated with it for about two days trying to run a simple "Hello World" program. Sometimes the only way to get to where you want to go is to follow the path :)