alternative solution of del command in batch file

November 3, 2016 at 13:43:14
Specs: Windows 10
Hello,

Do we have any alternative ways to delete images without using delete command?
I am trying to copy images from one folder to another.
I just want to copy images which starts with lastname,firstname-idnum.
I want to remove images which starts with hyphen (-)
I want to remove images which starts with numbers
I don't want to use del command on my production environment, so I am looking for safe and better solution.
Would you please give me appropriate solution for that asap?

I am also sharing my code with you but for some reason it is not working properly.
@echo off

robocopy c:\images c:\images2 /XN /XC /XO
cd c:\images2
del /r \ -*.JPG

cd c:\images2
del /r \ [0]*.JPG

cd c:\images2
del /r \ [0]*.JPG

cd c:\images2
del /r \ [1]*.JPG

cd c:\images2
del /r \ [2]*.JPG

cd c:\images2
del /r \ [3]*.JPG

cd c:\images2
del /r \ [4]*.JPG


Thanks


See More: alternative solution of del command in batch file

Report •

#1
November 3, 2016 at 15:59:28
1) "erase", but that probably won't gain you any yardage over "del"
2) "RD /S /Q" or "RMDIR": move all the files to a temp directory then remove the directory
3) You could get rid of all but one by using "move": create a dummy file and keep moving it to each file, but at the end you will still have one file, but with no content and a random name.
4) move the files (or file, if you used step 3) to a removable media and toss it, take it homem, or plug it into your laptop to finish the job offline.
5) VBscript - filesystemobject - .delete method

Your code: 1) I don't believe DEL has a /R option, (see: "DEL /?" for options)
2) You probably don't want a slash here (it points to the root of the drive), but rather a dot:
del /r \ [0]*.JPG
should be:
del .\[0]*.jpg

message edited by nbrane


Report •

#2
November 7, 2016 at 07:21:21
And what if I want to move those images which includes Aaron,Raul_1.JPG, Morgan,Jim_2.JPG.

Report •

#3
November 7, 2016 at 14:49:11
So you want to delete without deleting. To what end, exactly?

Also, as nbrane points out, your del command needs work. You're telling it to delete everything on the drive, as well as the various .JPG files. Thankfully for you, DEL doesn't have an /R switch (it's /S), so the command errors out without doing anything.

How To Ask Questions The Smart Way

message edited by Razor2.3


Report •
Related Solutions


Ask Question