Save file with same label with different type in python.

huangapple go评论70阅读模式
英文:

Save file with same label with different type in python

问题

我有几个带有相同标签但类型由日期确定的文件(例如,example.0411,example.0406,example0324)。
我想将所有这样的文件从一个文件夹移动到另一个文件夹。
为此,一旦我建立了SSH连接,我使用以下命令:

scp.get(host_folder+'example.0411', local_folder)

在存储这些文件的文件夹中,还有其他我不想复制的文件和文件夹。
由于我无法知道已添加了哪种类型的日期,有没有办法复制所有"example.something"?

英文:

I have several files with the same label but the type is given by the date (e.g. example.0411, example.0406, example0324).
I want to move all the files like this from a folder to another one.
To do so, once I've done an SSH connection, I'm using the command:

scp.get(host_folder+'example.0411', local_folder)

In the folder where these files are stored, there are other folders and files which I don't want to copy.
Since I can't know which kind of date has been added as type, is there a way to copy the all the "example.something"?

答案1

得分: 0

我使用了这个命令

stdin, stdout, stderr = ssh.exec_command('find ' + host_folder + ' -name ' + search_message)
for line in stdout:
    messaggio = line.strip('\n')
    print(messaggio)

然后我处理变量 messaggio 并重新创建路径以通过 scp.get() 传递。我百分之百确定有更好的方法……但我不是专业程序员。

英文:

I've used this command

stdin, stdout, stderr = ssh.exec_command('find '+host_folder+' -name '+ search_message)
for line in stdout:
    
    messaggio=line.strip('\n')
    print(messaggio)

than I work on variable messaggio and recreate the path to pass via scp.get()
I'm 100% sure it can be done better....but I'm not an expert programmer.

huangapple
  • 本文由 发表于 2023年4月13日 17:30:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76003857.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定