Skip to content

Instantly share code, notes, and snippets.

@nodewee
nodewee / copy-text-to-clipboard.js
Last active October 15, 2022 08:08
Copy text to clipboard (in the browser)
/*
Copy text to clipboard (in the browser)
Updated: 2022-10-14
Source: https://gist.github.com/NodeWee/a4df091ed6e4dc0e526e609daeb34cfd
*/
async function copyTextToClipboard(text) {
// Reference: https://stackoverflow.com/a/30810322/1293256
if (navigator.clipboard) {
// console.log('copy by navigator')
def list_files(
dir: str,
ext: list or str = None,
recursive: bool = True,
excludes: list = None,
):
"""
Args:
- dir, directory path.
- ext, file extension list, lowercase letters, such as ".txt". Default is None, which means all files.
def auto_rename_exist_filename(file_path):
"""
For example: a.txt, a(1).txt, a(2).txt
Source: https://gist.github.com/nodewee/9ae9b0b461b4bcaf30bc2b84ca8c4743.js
"""
if not os.path.exists(file_path):
return file_path
dir_path = os.path.dirname(file_path)