Page 1 of 1

file not erased

Posted: 2023-Dec-05, 5:11 pm
by daviaujp
Hi,

test.cmd


for /f "tokens=1,2 delims=." %I in ('dir /B/O:G *.mp4') do if EXIST %I del %I.mkv

>if EXIST jupe tututeen del jupe tututeen.mkv

The file is not erased even if I use quotes. "jupe tututeen.mkv"REgards,

JPD

Re: file not erased

Posted: 2023-Dec-05, 6:50 pm
by OJBakker
problems:
You post test.cmd
this suggests you refer to a batchfile.
Then you post code, not for a batchfile but for commandline.
Then you post a supposed result of your code that can not be the result of the code you posted.
The code you posted with the file "jupe tututeen.mkv" will result in an attempt to delete the file "jupe tututeen.mp4.mkv".
This delete will fail because this file does not exist.

Re: file not erased

Posted: 2023-Dec-06, 4:08 pm
by daviaujp
Robocopy.cmd

Code: Select all

.........................

::
robocopy "C:\ZZ COURS"   "D:\ZZ COURS"   /S  /FP  /NJH /NS /NDL /XX /XO /R:2 /IT

PUSHD "C:\Users\PC\Videos\Movavi Library"
 
for /f "tokens=1,2 delims=." %I in ('dir /B/O:G  *.mp4')  do if EXIST %I  del /Q  %I.mkv

 
robocopy  "C:\Users\PC\Videos\Movavi Library"    "D:\MovaviScreenCaptureStudio" *.mp4       /FP  /NJH /NS /NDL /XX /XO /R:2 /IT

::
PUSHD "C:\Users\PC\Videos\Movavi Screen Capture Studio"
 
for /f "tokens=1,2 delims=." %I in ('dir /B/O:G  *.mp4')  do if EXIST %I  del /Q  %I.mkv

::
.............................................
The batch has 77 lines
===================
On the command line:

C:\Users\PC\Videos\Movavi Library>for /f "tokens=1,2 delims=." %I in ('dir /B/O:G *.mp4') do if EXIST %I del /Q %I.mkv
C:\Users\PC\Videos\Movavi Library>if EXIST jupe tututeen DEL /Q jupe tututeen.mkv
C:\Users\PC\Videos\Movavi Library>echo %errorlevel%
0
The file is not deleted

Regards

JPD

Re: file not erased

Posted: 2023-Dec-06, 5:04 pm
by OJBakker
Ok, I see what i have missed in your code.
You are using the "delims=." as an unreliable method to split the filename and the extension.
The dir selects the file "jupe tututeen.mp4".
The if exist might work but only if "jupe tututeen" exists as file or directory.
The del will fail because of the space in the filename.
Try

Code: Select all

del /Q "%I.mkv"

Re: file not erased

Posted: 2023-Dec-06, 8:52 pm
by daviaujp

Code: Select all

C:\Users\PC\Videos\Movavi Library>for /f "tokens=1,2 delims=." %I in ('dir /B/O:G  *.mp4')  do if EXIST %I  del /Q "%I.mkv" && echo %errorlevel%

C:\Users\PC\Videos\Movavi Library>if EXIST jupe tututeen del /Q "jupe tututeen.mkv"   && echo 0

C:\Users\PC\Videos\Movavi Library>dir
 Le volume dans le lecteur C n’a pas de nom.
 Le numéro de série du volume est 42F4-8985

 Répertoire de C:\Users\PC\Videos\Movavi Library

2023-12-05  12:05    <DIR>          .
2023-10-27  06:50    <DIR>          ..
2023-10-27  06:51        73 721 216 jupe tututeen.mkv
2023-10-27  06:51        73 721 216 jupe tututeen.mp4
               2 fichier(s)      147 442 432 octets
               2 Rép(s)  153 911 738 368 octets libres
               
               

Re: file not erased

Posted: 2023-Dec-06, 9:42 pm
by OJBakker
The dir shows your code is doing what you tell it to do.
There is no file or directory with the name "jupe tututeen" (filename without extension).
So the if returns false and the del is skipped.

Re: file not erased

Posted: 2023-Dec-07, 2:07 am
by daviaujp
Yes!

Thank you very much. :-)

JPD

Re: file not erased

Posted: 2023-Dec-07, 3:46 pm
by daviaujp
In batch file

Code: Select all

for /f "tokens=1,2 delims=." %%I in ('dir /B/O:G  *.mp4')  do if EXIST "%%I".mp4  del /Q "%%I".mkv