c# - 如何使用 powershell 和 C# 从 adb 中获取所有文件
问题描述
嗨,我在 c# 中有自动化代码,我需要检查数据库文件是否已加密,但首先我需要将文件下载到我的机器中。
try
{
string path = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.FullName;
Directory.SetCurrentDirectory(path + "\\powershell\\");
using (PowerShell pshell = PowerShell.Create())
{
pshell.AddCommand("adb pull \"/data/data/app.name.tt/files/Database\"");
//pshell.AddScript(path + "\\powershell\\AdbPull.Ps1");
pshell.Invoke();
}
}
catch (DirectoryNotFoundException e)
{
Console.WriteLine("The specified directory does not exist. {0}", e);
}
首先我怎么知道文件下载到哪里?第二如何保存到特定文件夹?
解决方案
您有两种选择:
使用普通流程(推荐)
var adbPath = "C:/Program Files/ADB/adb.exe";
var command = "pull";
var whatToPull = "\"/storage/77F1-1BF3/sht/1.jpg\"";
var whereToPull = "\"C:/Users/picolino/adb/downloads\"";
Process.Start(adbPath, $"{command} {whatToPull} {whereToPull}");
使用 PowerShell(你的情况)
var adbPath = "C:/Program Files/ADB/adb.exe";
var command = "pull";
var whatToPull = "\"/storage/77F1-1BF3/sht/1.jpg\"";
var whereToPull = "\"C:/Users/picolino/adb/downloads\"";
using (var pShell = PowerShell.Create())
{
pShell.AddScript($"& '{adbPath}' {command} {whatToPull} {whereToPull}");
pShell.Invoke();
}
推荐阅读
- vba - 如何编写 VBA 宏以将重复任务添加到附加到 Azure DevOps 的项目中的 PBI
- java - Jacoco 覆盖率 0.0
- c# - 如何根据 c# 中的变量选择要使用的 where 子句?
- sql - 为什么左连接会导致优化器忽略索引?
- html - 为什么我的标志没有出现在我的导航栏上,但其他标志是的?
- java - Android Studio:微调器未显示数据库中的信息
- javascript - 在 Google Charts Maps 上让事件与 vue-google-charts 一起使用
- r - 在保留索引的同时取消列出列表
- python - 具有顺序问题的 Python 日期时间
- swift - 断言代码在单元测试中的某个时刻运行?