How to Create a Link to a Directory

How to create a link to a directory on linux

Symbolic or soft link (files or directories, more flexible and self documenting)

#     Source                             Link
ln -s /home/jake/doc/test/2000/something /home/jake/xxx

Hard link (files only, less flexible and not self documenting)

#   Source                             Link
ln /home/jake/doc/test/2000/something /home/jake/xxx

More information: man ln


/home/jake/xxx is like a new directory. To avoid "is not a directory: No such file or directory" error, as @trlkly comment, use relative path in the target, that is, using the example:

  1. cd /home/jake/
  2. ln -s /home/jake/doc/test/2000/something xxx

How to use ln create link for directories on linux?

You change the position of arguments ln [-fiqRrv] old new. The first position is original file/folder e the second is the symbolic link. Try this, that will create a symbolic link in test4 to test1

ln -s test1 test4

more in : ln documentation

Create a symbolic link of directory in Ubuntu

This is the behavior of ln if the second arg is a directory. It places a link to the first arg inside it. If you want /etc/nginx to be the symlink, you should remove that directory first and run that same command.

Create a link to folder with python and tkinter

You can try following this process:

from tkinter import *
import os

root = Tk()
# path = 'C:\Folder Name'
path = 'C:\Folder Name\File Name.docx'

def open():
os.startfile(path, 'open')

button = Button(root, text="Open File Direction or File", command=open)
button.pack()

root.mainloop()

Or this:

from tkinter import *
import os

def open():
os.system("start C:/")

root = Tk()
button = Button(root, text="Open File Direction", command=open)
button.pack()
root.mainloop()

PHP to create Links for files in a folder

You can add this function to help with getting the dates from the filenames

function getDateFromFileName($filename){
$dateObj = DateTime::createFromFormat('m-Y',substr($filename,1,2).'-'.substr($filename,3,6));
return $dateObj->format('F Y');
}

Calling getDateFromFileName("n102017.pdf") prints October 2017

EDIT:

To change the name in your scenario do

<?php
$dir = "var/newsletters/";

function getDateFromFileName($filename){
$dateObj = DateTime::createFromFormat('m-Y',substr($filename,1,2).'-'.substr($filename,3,6));
return $dateObj->format('F Y');
}
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
if($file == "." || $file ==".."){
continue;
}
$formatted_date = getDateFromFileName($file);
echo " <a href=var/newsletters/$file>{$formatted_date}</a><br>";
closedir($dh);
}
}
?>

How to create a symbolic link when target directory doesn't exist?

Try like this,

mkdir -p  /create_your_path/ && xargs ln -s /link_file_path/file /create_your_path/

How do I link back out of a folder using the a-href tag?

Try setting your link to be your site root as so; note the / in front of home.html:

<a href="/home.html">bla</a>

Or if you know the path is definitely one directory down then just explicitly tell it to go down 1 directory; note the ../ in front of the home.html.

<a href="../home.html">bla</a>


Related Topics



Leave a reply



Submit