【问题标题】:How to rename multiple files with adb?如何用 adb 重命名多个文件?
【发布时间】:2022-01-01 09:55:40
【问题描述】:

我想将/sdcard/Android/data/com.miui.gallery/files/gallery_disk_cache/small_size 文件夹中的所有文件重命名为更短的名称。 每个文件都是 65 个字符长,我希望它尽可能短,我的文件夹中有 +- 9000 个文件。文件名包含字母和数字。

我可以使用我的 Windows 电脑进行 adb 调试,并且 USB 调试已打开 但是我无法访问我的手机,它卡在引导循环中并且在 20 秒后关闭,触摸只能用于输入我的密码,以便我可以访问上述命名目录。

到目前为止,我已经提取了 5GB,但是 cmd 限制为 8000 个字符,并且在不先重命名文件的情况下提取所有内容需要很长时间

【问题讨论】:

    标签: android adb rename


    【解决方案1】:

    tasker 当然可以,但我不能给你“完整的食谱”。基本上,你可以像这样创建一个任务:

    Execute Command: ls -1 /path/to/your/files, and capture the output into a variable
    the command will list all files in the given directory, one file per line
    Work on the variable. There are possibilities to convert it into an array, so you can use a for loop to handle each file
    again with variables, you can setup the rename command (e.g. using Variable Search Replace) in a new variable. Pseudo-Code: mv "$old_name" "$(s/ /_/,$old_name)"
    

    但在某些终端应用程序(或通过 adb shell)中使用简单的 shell 脚本来实现同样的目的要容易得多:

    cd /path/to/your/files 对于 $(ls -1) 中的文件;做 mv "$file" "$(echo $file|sed 's/ /_/g')";完成

    【讨论】:

    • 您的命令似乎正在执行某些操作,但文件名保持不变。但是,我可以使用以下命令删除字符:'for file in *;做 mv -v "$file" "$(echo $file | sed 's/a//g')" ;完毕' 。但是我必须为每个字符运行它,我必须小心不要以这种方式创建双重文件名。我想用 1、2、3、...9000 替换每个文件的全部 65 个字符
    • 你的命令是为了删除空格
    猜你喜欢
    • 1970-01-01
    • 2015-07-19
    • 1970-01-01
    • 2015-08-22
    • 2017-04-07
    • 2021-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多