Are you migrating from the Windows Operating System to a Linux distribution and have shortcuts to your favorite websites stored on your Windows system?
Both Windows and Linux utilize a different file format for shortcuts. You cannot copy your Windows shortcuts to a Linux desktop and expect that they will work, because they won’t. You will need to convert them into a format that Linux understands.
Windows URL shortcuts are stored in text files that end with either “.url” or “.website”, whereas Linux shortcuts are stored in text files that simply end with “.desktop”. The only common property within both of the Windows and Linux shortcuts is the URL property.
Luckily, Python can handle this conversion for us. The Python script below will iterate through a given directory and convert all of your Windows shortcuts into Linux-compatible shortcuts.
#!/usr/bin/python3
import os
def convert(directory):
# Add all files from the directory into a list
files = os.listdir(directory)
# Iterate through the directory list
for file in files:
# Look for files ending in ".url" or ".website"
if file.endswith(('.url', '.website')):
# Set a file name without the file extension
filename = os.path.splitext(file)[0]
# Create new filename for Linux shortcut
new_filename = os.path.join(directory, filename+".desktop")
# Open and Read the file into memory
with open(os.path.join(directory, file), "r") as f:
# Loop through each line of the file
for line in f:
# Strip line breaks from the end of each line
line = line.rstrip()
# Find the line that starts with "url="
if "url=" in line.lower():
# Create new Linux shortcut
with open(new_filename, "w") as nf:
nf.write("[Desktop Entry]\n")
nf.write("Name=" + filename + "\n")
nf.write("Type=Link\n")
nf.write("Icon=text-html\n")
nf.write(line)
if __name__ == "__main__":
# Pass the Directory to the convert function
convert("/home/user/Desktop/Windows Shortcuts")






















