Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get file name of an icon file in a folder for creating/updating desktop.ini for folder(s)?
    primarykey
    data
    text
    <p>I need help returning the file name of a file located in a folder.</p> <p>I have read other questions asked a few times and the answer seems to be:</p> <pre><code>for /d %F in (*.*) do echo %~nxF </code></pre> <p>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.</p> <p>What I am trying to do is create a batch file that will read the icon file name, then enter the specific information into <code>desktop.ini</code> and finally create that file with the respective rights or attributes.</p> <pre><code>@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] &gt; %FOLDERINI% echo IconResource=\[Video]\[HD Films]\%FOLDERICO%\Icon\%FOLDERICO%.ico,0 &gt;&gt; %FOLDERINI% if not "%2"=="" ( echo FolderType=%2 &gt;&gt; %FOLDERINI% ) attrib -a +s +h %FOLDERINI% </code></pre> <p>I think the code could be improved somehow to run it from a root directory as opposed to the specific folder.</p> <p><strong>EDIT:</strong> Updated my file so it now looks like this:</p> <pre><code>@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] &gt; %ICOINI% echo IconResource=%ICODIR:~2%%ICO%,0 &gt;&gt; %ICOINI% if not "%2"=="" ( echo FolderType=%2 &gt;&gt; %ICOINI% ) attrib -a +s +h %ICOINI% Pause </code></pre> <p>Which I need to put into a for loop scanning each subdirectory of the root.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload