Page 1 of 1
Finding cause of "The filename, directory name, or volume label syntax is incorrect" error when deleting files [SOLVED]
Posted: 13 Jul 2023 05:08
by DOSadnie
This script
Code: Select all
@echo off
for /F "skip=1" %%D in ('wmic logicaldisk get caption') do (
cd /D %%D
del /AH /S /Q ~$*.xlsm
)
pause
goes through every drive [except the system one] and deletes
~$WHATEVER THE REST OF NAME.XLSM files. However it can produce an outcome like this
Could Not Find X:\~$*.xlsm
Deleted file - Y:\TEST1\~$some test file.xlsm
Deleted file - Z:\TEST2\~$another test file.xlsm
The filename, directory name, or volume label syntax is incorrect.
Could Not Find Z:\~$*.xlsm
which shows both that it does work but also is unable to access some folders [or maybe just files?] on volume
Z
Is there a way to pn point this erroneous path? How to make the
CMD window write where exactly it failed at accessing?
Re: Finding cause of "The filename, directory name, or volume label syntax is incorrect" error when deleting files blunt
Posted: 13 Jul 2023 09:11
by OJBakker
add
before the
line.
This will show which files are selected to be deleted.
It is probably a file with a space or % or poison character like & or | in the filename.
Re: Finding cause of "The filename, directory name, or volume label syntax is incorrect" error when deleting files blunt
Posted: 13 Jul 2023 09:57
by DOSadnie
As I had feared, the culprit is not what I am looking for but some other item
Because now this
Code: Select all
@echo off
for /F "skip=1" %%D in ('wmic logicaldisk get caption') do (
cd /D %%D
dir /AH /S "~$*.xlsm"
del /AH /S /Q ~$*.xlsm
)
pause
[with the exact same test locations and files as before] produces this
Volume in drive X is Archive#1
Volume Serial Number is F2EA-3C73
File Not Found
Could Not Find X:\~$*.xlsm
Volume in drive Y is Archive#2
Volume Serial Number is 5CCA-44F3
Directory of Y:\TEST1
2023-07-13 12:44 0 ~$some test file.xlsm
1 File(s) 0 bytes
Total Files Listed:
1 File(s) 0 bytes
0 Dir(s) 1,029,689,573,376 bytes free
Deleted file - Y:\TEST1\~$some test file.xlsm
Volume in drive Z is Archive#3
Volume Serial Number is 1693-51F1
Directory of Z:\TEST2
2023-07-13 12:44 0 ~$some test file.xlsm
1 File(s) 0 bytes
Total Files Listed:
1 File(s) 0 bytes
0 Dir(s) 358,623,019,008 bytes free
Deleted file - Z:\TEST2\~$another test file.xlsm
The filename, directory name, or volume label syntax is incorrect.
Volume in drive Z is Archive#3
Volume Serial Number is 1693-51F1
File Not Found
Could Not Find Z:\~$*.xlsm
Re: Finding cause of "The filename, directory name, or volume label syntax is incorrect" error when deleting files blunt
Posted: 13 Jul 2023 13:22
by OJBakker
Try again with echo ON.
This will show you were your code goes wrong!
Hint, there is nothing wrong with the filename or location.
Re: Finding cause of "The filename, directory name, or volume label syntax is incorrect" error when deleting files blunt
Posted: 15 Jul 2023 04:08
by DOSadnie
OJBakker wrote: ↑13 Jul 2023 13:22
[...]
Hint, there is nothing wrong with the filename or location.
And so it seems
Because now what I got was this
Code: Select all
X:\>(
cd /D P:
del /AH /S /Q ~$*.xlsm
)
Could Not Find P:\~$*.xlsm
Y:\>(
cd /D W:
del /AH /S /Q ~$*.xlsm
)
Deleted file - Y:\TEST2\~$some test file.xlsm
Z:\>(
/D
del /AH /S /Q ~$*.xlsm
)
The filename, directory name, or volume label syntax is incorrect.
Could Not Find Z:\~$*.xlsm
Z:\>cd /D C:\
So I went to the
Disk Management of Windows changed letters assignment and even reset the system- but the outcome is always the same: the very last volume spits this apparently untrue information
Hence the question: why?
And more importantly: how do I get rid of it?
Re: Finding cause of "The filename, directory name, or volume label syntax is incorrect" error when deleting files blunt
Posted: 15 Jul 2023 08:12
by OJBakker
Ok, next hint, try the following script, that should make it clear where your problems originate!
Code: Select all
@echo off
for /F "skip=1" %%D in ('wmic logicaldisk get caption') do (
echo Processing drive: [%%D]
cd /D %%D
dir /AH /S "~$*.xlsm"
del /AH /S /Q ~$*.xlsm
)
pause
Re: Finding cause of "The filename, directory name, or volume label syntax is incorrect" error when deleting files blunt
Posted: 16 Jul 2023 13:04
by DOSadnie
Now the
CMD window says
Processing drive: [Z:]
Volume in drive Z is Archive#3
Volume Serial Number is 1693-51F1
Directory of Z:\TEST2
2023-07-13 12:44 0 ~$another test file.xlsm
1 File(s) 0 bytes
Total Files Listed:
1 File(s) 0 bytes
0 Dir(s) 306,194,939,904 bytes free
Deleted file - Z:\TEST2\~$another test file.xlsm
]rocessing drive: [
The filename, directory name, or volume label syntax is incorrect.
Volume in drive Z is Archive#3
Volume Serial Number is 1693-51F1
File Not Found
Could Not Find Z:\~$*.xlsm
So for reasons for me unknown there is line
]rocessing drive: [
instead of
Processing drive: [Z]
which no wonder produces such error on the account of name
Re: Finding cause of "The filename, directory name, or volume label syntax is incorrect" error when deleting files blunt
Posted: 16 Jul 2023 14:00
by OJBakker
You still do not see what happens?
Drive Z: is completely processed. The error happens after that!
So your script tries to process 'something' after all the drives are processed and that is causing the error you are getting.
Re: Finding cause of "The filename, directory name, or volume label syntax is incorrect" error when deleting files blunt
Posted: 19 Jul 2023 09:53
by DOSadnie
No- apparently I just do not understand how CMD can insert such error in between two OK messages, all of them concerning the same last volume
And how is a user suppose to know that such error is a fake one and when it is a real one without having that altered script and being forced to carefully read thorough it
Re: Finding cause of "The filename, directory name, or volume label syntax is incorrect" error when deleting files blunt
Posted: 19 Jul 2023 12:56
by ShadowThief
wmic adds an extra carriage return (\r) at the end of its output (see
viewtopic.php?f=3&t=4266 for more details). A carriage return moves the cursor to the beginning of the line, so Processing Drive:[ is displayed, then the cursor is moved to the start of the line, and then ] is displayed, overwriting the first character.
Re: Finding cause of "The filename, directory name, or volume label syntax is incorrect" error when deleting files blunt
Posted: 19 Jul 2023 13:23
by OJBakker
Such a small script and you seem to fundamentally unable to interpreted what that script is doing.
There is nothing fake about the error message you get and your script is doing exactly what you programmed, although not what you intended it to do.
You intend to process a list of valid drive-identifiers.
What you are processing is wmic output.
What you intend to process and what you are processing is not the same thing!
The processing consists of 3 lines, ok 4 lines if you include the echo %%D line.
The echo line is not necessary but helps in understanding what is being processed. no problem. (See post from ShadowThief)
The dir/del lines produce a message for found/processed or a file not found message. no problem.
That leaves just one line, the change to drive %%D.
This succeeds with changing the drive or fails with an error message.
Not acting on this error or preventing this error from happening causes your script to continue with the dir/del lines after failing to switch to another drive.
So what is missing is sanity check on the %%D drive letters and/or error checking/handling on the change drive code.
Re: Finding cause of "The filename, directory name, or volume label syntax is incorrect" error when deleting files blunt
Posted: 21 Jul 2023 12:39
by DOSadnie
I came up with an alternative method
Code: Select all
@echo off
setlocal enabledelayedexpansion
set "LIST OF VOLUMES=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
set "PATTERN OF FILES=~$*.xlsm"
echo.Deleting from all volumes files
echo.
echo.%PATTERN OF FILES%
for %%d in (%LIST OF VOLUMES%) do (
echo.
echo.
echo.
echo.%%d:\
echo.
del /ah /s /q "%%d:\%PATTERN OF FILES%"
)
Thank you both for your help