Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
969 views
in Technique[技术] by (71.8m points)

rename - Batch file ren command access denied, but works when I type it myself

I have a batch file that copies the files from where Windows stores its Lock Screen images and puts them into my own personal folder, then renames them as .jpg's so that I can use them as my active desktop backgrounds, but for some reason the "ren" command has stopped working (Access denied). However, if I open a command prompt myself and type the command, it works.

It doesn't matter if I have the final destination folder open or not, I get the same results. I have also tried running the batch file as administrator and it didn't change anything.

My code is below. For troubleshooting, I added two timeout commands just so it would stop after a couple steps to let me see what was happening. The batch file is saved here: "C:UsersAdamDesktop"

xcopy "C:UsersAdamAppDataLocalPackagesMicrosoft.Windows.ContentDeliveryManager_cw5n1h2txyewyLocalStateAssets" "D:UsersAdamPicturesSpotlight" /y
d:
cd D:UsersAdamPicturesSpotlight
timeout /t 5 /nobreak
ren *.* *.jpg
timeout /t 30 /nobreak

Thanks in advance!

question from:https://stackoverflow.com/questions/65830919/batch-file-ren-command-access-denied-but-works-when-i-type-it-myself

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I see no reason why you cannot just do this with a single command.

This one uses the Standard location for the users profile directory as the destination:

Copy /Y "%LocalAppData%PackagesMicrosoft.Windows.ContentDeliveryManager_cw5n1h2txyewyLocalStateAssets*" "%UserProfile%PicturesSpotlight*.jpg"

If your location is really in the D: drive then:

Copy /Y "%LocalAppData%PackagesMicrosoft.Windows.ContentDeliveryManager_cw5n1h2txyewyLocalStateAssets*" "D:UsersAdamPicturesSpotlight*.jpg"

I both examples I have used the built-in copy command, there is no benefit in using the deprecated xcopy.exe utility for this, as you are not using any of its optional features.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...