file not erased

Microsoft Windows
Post Reply
daviaujp
Posts: 6
Joined: 2023-Nov-26, 2:46 am

file not erased

Post 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
OJBakker
Posts: 13
Joined: 2021-Jul-29, 7:06 am

Re: file not erased

Post 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.
daviaujp
Posts: 6
Joined: 2023-Nov-26, 2:46 am

Re: file not erased

Post 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
OJBakker
Posts: 13
Joined: 2021-Jul-29, 7:06 am

Re: file not erased

Post 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"
daviaujp
Posts: 6
Joined: 2023-Nov-26, 2:46 am

Re: file not erased

Post 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
               
               
OJBakker
Posts: 13
Joined: 2021-Jul-29, 7:06 am

Re: file not erased

Post 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.
daviaujp
Posts: 6
Joined: 2023-Nov-26, 2:46 am

Re: file not erased

Post by daviaujp »

Yes!

Thank you very much. :-)

JPD
daviaujp
Posts: 6
Joined: 2023-Nov-26, 2:46 am

Re: file not erased

Post 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
Post Reply