Code: Select all
fsutil file setshortname "%cd%\test.tmp" blah
This also works for folders.
Moderator: DosItHelp
Code: Select all
fsutil file setshortname "%cd%\test.tmp" blah
Code: Select all
The modifiers can be combined to get compound results:
%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line
Code: Select all
@echo off
cls
setlocal
set "filename=a filename with, a comma [1].txt"
if not exist "%filename%" ((echo test)>"%filename%")
if not exist "%SystemRoot%\system32\command.com" echo this workarround needs command.com.
:: get short form of the absolute file name
pushd .
%SystemRoot%\system32\command.com /? >nul 2>nul
set /A "N=2" & for %%a in ("%filename%") do for %%a in (%%~ta) do set /A "N+=1"
for /F "tokens=%N%" %%a in ('^(dir "%filename%" /X 2^>^&1^)^| findstr /L /C:"%filename%"') do set "sfile=%CD%\%%~a"
popd
echo WMIC DATAFILE WHERE name="%sfile:\=\\%" GET lastmodified | find "."
WMIC DATAFILE WHERE name="%sfile:\=\\%" GET lastmodified | find "."
pause
endlocal
goto :eof
Code: Select all
@echo off
pushd .
echo actual path: %CD%
%SystemRoot%\system32\command.com /? >nul 2>nul
echo short path: %CD%
popd
Code: Select all
c:\>echo test>c:\test.file
c:\>wmic DataFile where 'path like "%C:\\test.file.bat%"' get lastmodified
Code: Select all
Z:\>md test.path
Z:\>echo test>"z:\test.path\test.file"
Z:\>echo test2>"z:\test.path\test2.file"
Z:\>wmic DataFile where 'drive="Z:" and path like "%test.path%"' get lastmodified
LastModified
20140127121614.497867+060
20140127121618.834630+060
Z:\>wmic DataFile where 'drive="Z:" and path like "%test%"' get lastmodified
LastModified
20140127121614.497867+060
20140127121618.834630+060
c:\tmpf>cd c:\
c:\>md tmpf2
c:\>cd tmpf2
c:\tmpf2>echo a>testFileWithUniqueName
c:\tmpf2>wmic DataFile where 'drive="C:" and name like "%testFileWithUniqueName%"' get lastmodified,path,name
No Instance(s) Available.
c:\tmpf2>wmic DataFile where 'drive="C:" and path like "%testFileWithUniqueName%"' get lastmodified,path,name
No Instance(s) Available.
c:\tmpf2>wmic DataFile where 'drive="C:" and name like "%tmpf2%"' get lastmodified,path,name
No Instance(s) Available.
c:\tmpf2>wmic DataFile where 'drive="C:" and path like "%tmpf2%"' get lastmodified,path,name
No Instance(s) Available.
Code: Select all
Z:\>test
Z:\>md tmpf2
Z:\>cd tmpf2
Z:\tmpf2>echo a 1>testFileWithUniqueName
Z:\tmpf2>echo b 1>b
Z:\tmpf2>wmic DataFile where 'drive="Z:" and name like "%testFileWithUniqueName%"' get lastmodified,path,name
LastModified Name Path
20140127183824.143528+060 z:\tmpf2\testfilewithuniquename \tmpf2\
Z:\tmpf2>wmic DataFile where 'drive="Z:" and path like "%testFileWithUniqueName%"' get lastmodified,path,name
Keine Instanzen verfügbar.
Z:\tmpf2>wmic DataFile where 'drive="Z:" and name like "%tmpf2%"' get lastmodified,path,name
LastModified Name Path
20140127183824.153542+060 z:\tmpf2\b \tmpf2\
20140127183824.143528+060 z:\tmpf2\testfilewithuniquename \tmpf2\
Z:\tmpf2>wmic DataFile where 'drive="Z:" and path like "%tmpf2%"' get lastmodified,path,name
LastModified Name Path
20140127183824.153542+060 z:\tmpf2\b \tmpf2\
20140127183824.143528+060 z:\tmpf2\testfilewithuniquename \tmpf2\
Code: Select all
set "testFileWithUniqueName=abc"
set "tmpf2=def"
Code: Select all
set "prop=LastModified"
set lm1=CreateObject(""Scripting.FileSystemObject""^).^
GetStandardStream(1^).Write GetObject(""winMgmts:CIM_DataFile.Name
set lm2=""^).%prop%:Close
for /f %%m in ('mshta vbscript:execute("%lm1%='%~dpf1'%lm2%"^)') ^
do echo(file "%~nx1" last modified on: %%m
Sponge Belly wrote:I realised Foxi was talking about square brackets in the filename and not the parentheses around the name clause of the wmic command.
Code: Select all
wmic os get localdatetime
Sponge Belly wrote:
Btw, does anyone know how to do the mshta equivalent of the following:Code: Select all
wmic os get localdatetime
It might prove useful.
TIA!
- SB
Code: Select all
set ^"js=javascript:close(new ActiveXObject('Scripting.^
FileSystemObject'^).GetStandardStream(1^).Write(new String(new ^
Enumerator(new ActiveXObject('WbemScripting.SWbemLocator'^).^
ConnectServer('.','root\\cimv2'^).ExecQuery('Select LocalDateTime ^
from Win32_OperatingSystem where Primary=True'^)^).item(^).^
LocalDateTime^)^)^);^"
for /f %%t in ('mshta "%js%"') do echo(WMI LocalDateTime: %%t