I get an error ", - Invalid alias verb."
Code: Select all
@echo off
set "file=a filename with, a comma.txt"
echo text>"%file%"
WMIC DATAFILE WHERE name="%file%" get lastmodified | find "."
pause
Moderator: DosItHelp
Code: Select all
@echo off
set "file=a filename with, a comma.txt"
echo text>"%file%"
WMIC DATAFILE WHERE name="%file%" get lastmodified | find "."
pause
WMIC DATAFILE WHERE (name="%file%") get lastmodified | find "."
Keine Instanzen verfügbar.
Code: Select all
@echo off
set "file=%~dp0a filename with, a comma.txt"
echo text>"%file%"
WMIC DATAFILE WHERE name="%file:\=\\%" get lastmodified | find "."
pause
Code: Select all
X:\> set "fn=%cd%\tom, dick & harry.txt"
X:\> type nul >"%fn%"
X:\> wmic datafile where (name="%fn:\=\\%") get lastmodified
LastModified
20140121191739.539644+000
does the file exist ?AiroNG wrote:I may have a solution:WMIC DATAFILE WHERE (name="%file%") get lastmodified | find "."
however, if i run your script with the parenthesis i get another error:Keine Instanzen verfügbar.
it should translate to something like "No instances available".
Code: Select all
@echo off &setlocal disableDelayedExpansion
ver
set "f=c:\\___.txt"
echo.>"%f%"
WMIC DATAFILE WHERE ( name='%f%' AND Archive='TRUE' ) get lastmodified | find "."
set "f=c:\\_,_.txt"
echo.>"%f%"
WMIC DATAFILE WHERE ( name='%f%' AND Archive='TRUE' ) get lastmodified | find "."
pause
Code: Select all
Microsoft Windows XP [versie 5.1.2600]
20140121213757.484375+060
20140121213757.484375+060
Druk op een toets om door te gaan. . .
Code: Select all
C:\Users\User\TEST>set "f=c:\\_,_.txt"
C:\Users\User\TEST>for /f %a in ('WMIC DATAFILE WHERE ( name^='%f%' AND Archive^='TRUE' ^) get lastmodified ^| find "."') do @echo %a
No Instance(s) Available.
Code: Select all
C:\Users\User\TEST>set "f=c:\\_,_.txt"
C:\Users\User\TEST>for /f %a in ('"WMIC DATAFILE WHERE name='%f%' get lastmodified | find ".""') do @echo %a
, - Invalid alias verb.
Code: Select all
C:\Users\User\TEST>set "f=c:\\_,_.txt"
C:\Users\User\TEST>for /f %a in ('^"WMIC DATAFILE WHERE name='%f%' get lastmodified ^| find "."^"') do @echo %a
c:\\_ _.txt - Invalid alias verb.
Code: Select all
X:\> set "fn=%cd%\tom, dick & harry.txt"
X:\> type nul >"%fn%"
X:\> for /f "skip=1" %f in ('
More? wmic datafile where (name^="%fn:\=\\%"^) get lastmodified
More? ') do @echo(%f
20140121224248.567011+000
Code: Select all
Datenträger in Laufwerk Z: ist Test
Volumeseriennummer: 0123-4567
Verzeichnis von Z:\
23.01.2014 01:21 0 A_B~1.TXT a, b.txt
23.01.2014 01:21 0 A_B~2.TXT a,b.txt
2 Datei(en) 0 Bytes
0 Verzeichnis(se), 162.422.374.400 Bytes frei
Code: Select all
@echo off
setlocal
set "filename=a filename with, a comma.txt"
set "file=%~dp0%filename%"
for /F "tokens=1-3*" %%a in ('dir /X "%filename%" ^| findstr /R /C:"%filename%"') do set "shortname=%%d"
call set "shortname=%%shortname:%filename%=%%|"
for /L %%a in (1,1,11) do set "shortname=%shortname: |=|%"
set "shortname=%shortname:|=%"
set "sfile=%~dp0%shortname%"
WMIC DATAFILE WHERE name="!sfile:\=\\!" GET lastmodified | find "."
pause
endlocal
Code: Select all
@echo off
setlocal
set "filename=a filename with, a comma.txt"
echo abc>"%filename%"
for /F "delims=" %%a in ('dir /X "%filename%" ^| findstr /I /R /C:"%filename%"') do set "line=%%a"
set "shortname=%line:~36,12%"
set "shortname=%shortname: =%"
if defined shortname (set "filename=%~dp0%shortname%") else (set "filename=%~dp0%filename%")
WMIC DATAFILE WHERE name="%filename:\=\\%" GET lastmodified | find "."
pause
endlocal
Code: Select all
@echo off
setlocal
set "filename=a filename with, a comma.txt"
if not exist "%filename%" echo test>"%filename%"
for %%a in ("%filename%") do set "sfile=%%~sdpnxa"
WMIC DATAFILE WHERE name="%sfile:\=\\%" GET lastmodified | find "."
pause
endlocal
penpen wrote:This "=%line:~36,12%" part seems to on all systems with default short date format (TT.MM.JJJJ), but if other date formats are in use (for example "T.M.JJ" or "TTTT, TT.MM.JJJJ") it may slides to the left or right.
for %%a in ("%filename%") do set "sfile=%%~sdpnxa"
Code: Select all
@echo off
cls
setlocal
set "filename=a filename with, a comma [1].txt"
if not exist "%filename%" echo test>"%filename%"
for %%a in ("%filename%\") do set "buffer=%%~dpnxa"
set "N=-1"
for %%a in ("%buffer:\=" "%") do set /A "N+=1"
for %%a in ("%filename%\") do set "buffer=%%~sdpa"
set "M=0"
set "sfile="
setlocal enabledelayedExpansion
for %%a in ("%buffer:\=" "%") do (
set /A "M+=1"
if !M! LEQ !N! set sfile=!sfile! "%%~a"
)
endlocal & set sfile=%sfile%
set sfile=%sfile:" "=\%
set "sfile=%sfile:"=%"
set "sfile=%sfile: =%"
echo %sfile%
echo WMIC DATAFILE WHERE name="%sfile:\=\\%" GET lastmodified | find "."
pause
endlocal