【发布时间】:2020-11-06 21:29:38
【问题描述】:
你好,正如标题所说,我正在编写一个从 chrome 复制数据的程序。我当前的代码是
#library imports
import sys
import shutil
import os
import subprocess
#search and find requried files.
os.path.expanduser('~user') #search for user path
#Making directory
newpath = r'F:\Evidence\Chromium'
newpath = r'F:\Evidence\Chrome'
#Copy chrome file
original = r'%LOCALAPPDATA%\Google\Chrome\User Data\Default\History'
target = r'F:\Evidence\Chrome'
shutil.copyfile(original, target)
我在original = r'%LOCALAPPDATA%\Google\Chrome\User Data\Default\History'一行收到一个错误
我假设脚本无法读取%LOCALAPPDATA%\ 并且需要正确的用户路径?
在windows电脑上输入用户目录需要什么代码?
例如C:\Users\(Script to find out this part)\AppData\Local\Google\Chrome\User Data\Default
Scripv3.py", line 25, in <module>
shutil.copyfile(original, target)
File "C:\Users\darks\AppData\Local\Programs\Python\Python39\lib\shutil.py", line 261, in copyfile
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: '%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default\\History'
【问题讨论】:
-
请发布带有完整错误文本的回溯消息。
-
无法复制。
shutil.copyfile上会出现错误是有道理的,因为 %LOCALAPPDATA% 没有展开,但文字字符串分配本身没有我可以看到的问题。 -
stackoverflow.com/questions/13184414/… 的可能重复项;不过,如果不立即结束问题,我不能投票结束自己。