I need help returning the filename of a file located in a folder.
I have read this question asked a few times and the answer seems to be:
for /d %F in (*.*) do echo %~nxF
Although this seems to work for everyone else, when I run this within a batch file it has an exception and states that '~nxF' is not expected at this time.
What I am trying to do is create a batch file that will read the icon filename, then enter the specific information into Desktop.ini and finally create that file with the respective rights or attributes.
@echo off
set NAME=%~dp0
for %%* in (.) do set NAME=%%~n*
set FOLDERICO=%NAME%
set ICONSIZES=16 24 32 48 64 128 256
set FOLDERINI=Desktop.ini
attrib +s "%CD%"
if exist %FOLDERINI% attrib -s -h %FOLDERINI%
echo [.ShellClassInfo] > %FOLDERINI%
echo IconResource=\[Video]\[HD Films]\%FOLDERICO%\Icon\%FOLDERICO%.ico,0 >> %FOLDERINI%
if not "%2"=="" (
echo FolderType=%2 >> %FOLDERINI%
)
attrib -a +s +h %FOLDERINI%
I think the code could be improved some what so it can but run from a root directory as opposed to the specific folder.
EDIT: Updated my file so it now looks like this:
@ECHO OFF
attrib +s "%CD%"
set ICODIR=%CD%\Icon\
for %%F in ("%ICODIR%"*.ico) do set ICO=%%~nxF
echo %ICO%
set ICOINI=Desktop.ini
if exist %ICOINI% attrib -s -h %ICOINI%
echo [.ShellClassInfo] > %ICOINI%
echo IconResource=%ICODIR:~2%%ICO%,0 >> %ICOINI%
if not "%2"=="" (
echo FolderType=%2 >> %ICOINI%
)
attrib -a +s +h %ICOINI%
Pause
Which I need to put in a for loop scanning each sub directory of the root.
I need help returning the filename of a file located in a folder.
I have read this question asked a few times and the answer seems to be:
for /d %F in (*.*) do echo %~nxF
Although this seems to work for everyone else, when I run this within a batch file it has an exception and states that '~nxF' is not expected at this time.
What I am trying to do is create a batch file that will read the icon filename, then enter the specific information into Desktop.ini and finally create that file with the respective rights or attributes.
@echo off
set NAME=%~dp0
for %%* in (.) do set NAME=%%~n*
set FOLDERICO=%NAME%
set ICONSIZES=16 24 32 48 64 128 256
set FOLDERINI=Desktop.ini
attrib +s "%CD%"
if exist %FOLDERINI% attrib -s -h %FOLDERINI%
echo [.ShellClassInfo] > %FOLDERINI%
echo IconResource=\[Video]\[HD Films]\%FOLDERICO%\Icon\%FOLDERICO%.ico,0 >> %FOLDERINI%
if not "%2"=="" (
echo FolderType=%2 >> %FOLDERINI%
)
attrib -a +s +h %FOLDERINI%
I think the code could be improved some what so it can but run from a root directory as opposed to the specific folder.
EDIT: Updated my file so it now looks like this:
@ECHO OFF
attrib +s "%CD%"
set ICODIR=%CD%\Icon\
for %%F in ("%ICODIR%"*.ico) do set ICO=%%~nxF
echo %ICO%
set ICOINI=Desktop.ini
if exist %ICOINI% attrib -s -h %ICOINI%
echo [.ShellClassInfo] > %ICOINI%
echo IconResource=%ICODIR:~2%%ICO%,0 >> %ICOINI%
if not "%2"=="" (
echo FolderType=%2 >> %ICOINI%
)
attrib -a +s +h %ICOINI%
Pause
Which I need to put in a for loop scanning each sub directory of the root.
0 commentaires:
Enregistrer un commentaire