Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...