Fastest way to copy the full path of a file and insert it into a script - windows

In many task I've to open a file with a script so I've to type the full path of the file. Usually I go to properties of the file and then I copy the path and then the name of the file. I wonder if there is a faster way to do that.
I would like to copy it in one click or drag the file in the IDE or something like that....
(I'm using Windows XP, Mac Mountain Lion and Ubuntu 12.04 sometimes).

In windows pressing shift and right-click allows you to select copy path.
In Mac right click and pressing alt allows copying file as path.
I've found Copy path for Windows that:
that will allow you to right click on a drive or file system object
and copy the path of the file to the clipbpoard. If the drive is a
mapped drive or the file system object exits on a mapped drive it will
resolve the full UNC path.
On Windows Shift+Right Click allows you to copy the path directly.
Alternatively many shell (like the shells of Spyder and Canopy,Ipython) support a drag and drop option that allow you to drag the file inside the shell and get the path of the file.

Related

Change location to shortcut location

I am launching a script with a powershell shortcut (C:\Windows....\powershell.exe -file 'D:\powershell\script.ps1').
Is there a way to make script change its current location to location of said shortcut?
Example: Script itself is in D:\powershell\ and the shortcut is in C:\Work\Project1. I need the script to cd to "C:\Work\Project1\".
Thanks
You can make a shortcut that starts in whatever directory it's located in. All you have to do is modify the "Starts In" property of the shortcut, and blank it out. That's right. Set it to nothing.
Then, when you want to invoke the shortcut, navigate to the folder (directory) where it's located before invoking it. I use this technique for a shortcut that launches powershell but doesn't launch a script. I haven't tested it with a shortcut that launches a script.
Walter Mitty's helpful answer provides an effective solution, provided that the shortcut file is opened from either the Desktop or File Explorer.
This answer provides background information.
You must configure the desired working directory as part of the shortcut file, because the script you invoke knows nothing about the shortcut that invoked it.
Therefore, to configure a specific working directory (e.g., C:\Work\Project1), specify it in the shortcut file's Properties dialog in the Start in: field.
In case you want to update a shortcut file's (*.lnk) working directory programmatically, use the technique from this answer with the .WorkingDirectory property.
Note: In both cases, only an absolute path can be configured as the working directory: File Explorer only allows you to enter an absolute path anyway, and while the programmatic method allows you to assign a relative path, it is instantly resolved to an absolute one, relative to the shortcut's location.
To make the shortcut's own directory the working directory, you can blank out the Start in: field / .WorkingDirectory property, but note the limitations:
Only works when such a shortcut is either opened from either the Desktop or from File Explorer.
By contrast, opening it from the taskbar or (pre-Windows 10 only) the Start Menu, the working directory is $env:windir\System32 (typically, C:\Windows\System32).
If the shortcut targets an application (rather than a document), as in this case, that application invoked by the shortcut - including cmd.exe and powershell.exe - starts in the configured / implied working directory.
Caveat re cmd.exe: If the working directory is specified as as a UNC path, cmd.exe won't be able to change to that directory; as a workaround, use a path with a mapped drive instead (but, obviously, that drive must be mapped at the time the shortcut is opened).
You can use the TargetPath property of the shortcut (maybe do a get-childitem $psscriptroot where name is like scriptname and extension is like .lnk) with the set-location cmdlet
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-location?view=powershell-6

How to copy path of a file in Mac OS?

I am looking for a shortcut to copy the path of a file in Mac OS. I generally require it to copy paste in editor.
All you need to do to copy any items path name directly to the clipboard from anywhere in the file system:
Navigate to the file or folder you wish to copy the path for Right-click (or Control+Click, or a Two-Finger click on trackpads) on the file or folder in the Mac Finder
While in the right-click menu, hold down the OPTION key to reveal the “Copy (item name) as Pathname” option, it replaces the standard Copy option
Once selected, the file or folders path is now in the clipboard, ready to be pasted anywhere
The copied pathname is always the complete path, it’s not relative.
More details on the following link: http://osxdaily.com/2015/11/05/copy-file-path-name-text-mac-os-x-finder/
Try with shortcut command+option+C:
Cmd-Opt-C

View this file in Explorer (while open in notepad++)

I have file.txt opened in notepad++.exe
This works with all filetypes (.xlsx .txt .tab .csv .pages .scrivener you get it) on OS X:
I right click the file name using the app I'm in. (On notepad++ on windows, this would be right clicking on my file.txt file.)
A menu pops up, showing me the path to that file. For example /dropbox/work/projectA/subfolderB/file.txt
I choose a certain folder, for example the folder /projectA
That folder opens up in finder.
I want to do this on windows 7. Extra important to do it in notepad++ with .txt-files, since those are part of my GTD-system.
The question is not at all clear about what you want.
Having installed Notepad++ via the normal installer, you should be able to right-click on a file in Windows Explorer (or File Explorer) and select "Edit with Notepad++". That allows any file to be viewed with Notepad++.
The Notepad++ Run menu should contain an entry for Open containing folder that opens Windows Explorer at the folder containing the current file. This command shoul dbe in the file c:\Users\{UserName}\AppData\Roaming\Notepad++\shortcuts.xml. The shortcuts file on My Windows 7 computer contains the line
<Command name="Open containing folder" Ctrl="no" Alt="no" Shift="no" Key="0">explorer $(CURRENT_DIRECTORY)</Command>
If you need to alter the shortcuts file then do not use Notepad++, use another editor.

How to create a universal windows shortcut?

I have created a shortcut for my program (under Windows 7), whose target is in a sub-directory. But when I zip everything and send it to my colleague, the shortcut wont work because it the target directory cannot be found, it is like:
Target: C:\Users\my_user_name\Desktop\my_program\sub_directory\my_program.exe
and the shortcut is in C:\Users\my_user_name\Desktop\my_program\
When I send it to another PC, my_user_name directory cannot be found and shortcut doesnt work. How to solve this?
Create a batch file that launches the program. You can then use a relative path.
e.g.
C:\Users\my_user_name\Desktop\my_program\launch.cmd
cd sub_directory
start my_program.exe
possible solutions:
place the program with the exe on disk like c:\program\programname\ Location must be the same on all computers.
place the program with the exe on the network where you can both access, shortcut is the same
edit the shortcut in notepad and change the user

How do you add Start->Run shortcuts in Windows XP?

Does anyone know how you setup new commands to launch an application from the Start->Run box?
ie. you can type "firefox", "winword" or "excel" into the Run box and those applications will open even though they're not in the system path, but others won't. For example, with Firefox, there's no files named firefox.* in any of my system path directories:
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Subversion\bin;c:\Program Files\Microsoft
SQL Server\90\Tools\binn\
So there must be some way of linking applications with this path to create a shortcut command, maybe in the registry?
For example, I want to be able to launch Google Talk from the Run command, but typing the executable's name "googletalk.exe" doesn't do anything, which makes sense because it's not in the system path, but neither is firefox.exe, and typing "firefox" works.
Does anyone have any ideas?
From http://commandwindows.com/runline.htm:
Adding applications to the Path
Alternatively, the Registry can be
edited to explicitly contain the path
to the desired executable file or
files. The Registry key involved
isHKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App
Paths
Create a new sub-key with the name of the executable file that you
wish to add to the path. e .g.,
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App
Paths\somefile.exe
In this new key, add a string variable named "Path" containing the
value of the the path to your new
executable file, e.g., C:\Program
files\newprogramfolder\
The new key will already have an empty variable (Default). Edit it to
have the string value of entire
address of the new program executable , e.g., C:\Program files\newprogramfolder\somefile.exe
3 steps.
Create a shortcut to the foo.exe you want to run (foo.lnk)
Copy the foo.lnk to your C:\windows directory.
Run foo.exe by simply typing "foo" in your run dialog. ("start foo" in cmd prompt works too)
You could also use an application launcher like Launchy, Slickrun or Executor. That way you wouldn't have to mess with the registry. I use Executor and I can just select "send to -> executor" to create a shortcut for any app (or folder or whatever).
Run works with search paths, which include the Path environment variable and some others. There might be more information in the MSDN, give me a moment and I'll look it up.
I put a link to the application I want to launch in the "c:\windows" folder, and I use it all the time. You can also rename the link file, of course, to speed up things: for example, I type w, x or pp to launc Word, eXcel or PowerPoint.

Resources