Try   HackMD
HackMD Error: 404 error

Python OS Notes

tags: Python OS Google Drive Notes

將某個資料夾內的 mp4 檔存入各自同檔名的資料夾

import glob, os import re # 設定路徑 os.chdir('G:\\我的雲端硬碟\\Learning\\uni-app\\uni-app 課程一\\video') for file in glob.glob('*.mp4'): dir_name = re.findall('.*(?=\.mp4)', file)[0] # 資料夾檔名 if not os.path.exists(dir_name): os.mkdir(dir_name) # 建立資料夾 os.rename(file, dir_name + '/' + file) # 移動檔案進資料夾

rar 檔輸入包含中文的密碼解壓縮後刪除檔案

Windows 要先下載並安裝:
http://www.rarlab.com/rar/UnRARDLL.exe

安裝完成後加入系統環境變數:
變數名稱:UNRAR_LIB_PATH
變數值:C:\Program Files (x86)\UnrarDLL\x64\UnRAR64.dll

若要輸入中文的解壓縮密碼,要先修改 rarfile.py 中的b(x)
return x.encode('cp437')return x.encode('cp950')

from unrar import rarfile import os rar = rarfile.RarFile('Z:/path/to/rarfile.rar') rar.extractall('Z:/path/to/output_folder', pwd='有中文的密碼') os.remove('Z:/path/to/rarfile.rar')

將文字複製到剪貼簿

import pyperclip to_copy = '要複製的文字\n有換行' pyperclip.copy(to_copy)

下載 Google Drive 連結

應該需事先知道檔名及副檔名?
否則只能自訂

import gdown gdown.download('https://drive.google.com/uc?id=' + download_id, 'Z:/path/to/file.rar', quiet=False)