用户输入文件路径
User input into file path
对于这样的初学者问题,我深表歉意,但我正在尝试创建一个脚本,用户可以使用该脚本从我的 sftp 服务器获取文件名。目录基本上是 /files/year/month/day 所以一个例子是 files/2017/1/23.
我正在尝试获取用户输入以打印出他们想要的特定目录的文件名。我认为我的问题与将“/”合并到输入路径中有关。但这是我的第一个项目,我可以完全离开。感谢您在这里的任何输入。
import pysftp as sftp
year = int(input("Enter year of event: "))
month = int(input("Enter month of event: "))
day = int(input ("Enter day of event: "))
srv = sftp.Connection(host="hostname", username="user",
password="pass")
srv.chdir("recordings/'year'/'month'/'day'")
for filename in sorted(srv.listdir()):
if filename.startswith('web') and filename.endswith('.mp4'):
print (filename)
srv.close()
将 srv.chdir("recordings/'year'/'month'/'day'")
行更改为以下
srv.chdir("recordings/%s/%s/%s"%(year,month,day))
希望对您有所帮助!
对于这样的初学者问题,我深表歉意,但我正在尝试创建一个脚本,用户可以使用该脚本从我的 sftp 服务器获取文件名。目录基本上是 /files/year/month/day 所以一个例子是 files/2017/1/23.
我正在尝试获取用户输入以打印出他们想要的特定目录的文件名。我认为我的问题与将“/”合并到输入路径中有关。但这是我的第一个项目,我可以完全离开。感谢您在这里的任何输入。
import pysftp as sftp
year = int(input("Enter year of event: "))
month = int(input("Enter month of event: "))
day = int(input ("Enter day of event: "))
srv = sftp.Connection(host="hostname", username="user",
password="pass")
srv.chdir("recordings/'year'/'month'/'day'")
for filename in sorted(srv.listdir()):
if filename.startswith('web') and filename.endswith('.mp4'):
print (filename)
srv.close()
将 srv.chdir("recordings/'year'/'month'/'day'")
行更改为以下
srv.chdir("recordings/%s/%s/%s"%(year,month,day))
希望对您有所帮助!