How to copy path of a file in Mac OS? - macos

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

Related

How to create a link without .lnk extension?

If I have a file named "C\Test\mypic.jpg", can I create a shortcut with path "C\Test2\mypic.jpg"? Windows always seems to add a ".lnk" suffix, which is unwanted in my case.
Link in this case can mean several things but we can unpack all the possible scenarios:
A shortcut (.lnk file). These files must have the .lnk extension because the file extension is how Windows decides which handler to invoke when you double-click/execute the file. If you create a shortcut to a jpg file the real name can be link.jpg.lnk but the user will see the name as link.jpg in Explorer because .lnk is a special extension that is hidden.
A symbolic link (symlink). These are links on the filesystem level and can have any extension. mklink "c:\mylink.jpg" "c:\file.jpg"
A hardlink. This is another name for the same file (alias), it does not create a shortcut. mklink /H "c:\anothername.jpg" "c:\file.jpg"

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 unzip several *.zip archive files into separate folders?

I searched with Google but I didn't find something for Windows.
How can I extract several files into several folders?
For example: a.zip, b.zip and c.zip into the folders a, b and c.
I am looking for a command prompt command or a batch file solution.
Thanks
With using WinRAR in GUI mode:
Start WinRAR.
Select all the *.zip files.
Click on icon Extract To in toolbar.
Enter destination folder or browse to destination folder.
Check the option Extract archives to subfolders in group Miscellaneous.
Click on button OK.
In case of you want to know more about those extracting options, click before on button Help.
Or use from command line with current directory containing the *.zip files and all archive files which should be also extracted into subfolders of current directory with name of ZIP file as folder name:
"%ProgramFiles%\WinRAR\WinRAR.exe" x -ad -cfg- -ibck *.zip
How to build such a WinRAR command line?
Start WinRAR.
Click in menu Help on Help topics.
Click on tab Contents on list item Command line mode.
Click on list item Command line syntax, read this help page and copy the bold line into a text editor or into a command prompt window.
Click on tab Contents on list item Commands.
Click on list item Alphabetic commands list and replace <command> in text editor or command prompt window by most suitable command letter for the task.
Click on tab Contents on list item Switches.
Click on list item Alphabetic switches list and replace -<switch1> -<switchN> in text editor or command prompt window by those switches which are useful for the task.
Replace the rest of the WinRAR command line in text editor or command prompt window by the appropriate file and/or folder names.
The short explanation of the most important switch -ad for this task is:
-ad append archive name to destination path
As it can be seen here, WinRAR supports even a wildcard pattern as archive file name for extracting all archives files matching the pattern.
One more method exists with shell integration enabled as by default after installation of WinRAR.
Select the archive files to extract in file manager (Windows Explorer).
Click with secondary (right) mouse button on one of the selected files to open the context menu.
Open context submenu WinRAR if there is such a submenu because of enabled setting Cascaded context menus in WinRAR - Options - Settings - Integration.
Click on context menu item Extract each archive to separate folder.

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.

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

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.

Resources