- 1 year ago
For Loop /D Not Working for Network Attached Drives
The /D
option for the for
command in Windows is used to process folders in a specified directory. However, it may not work as expected for network attached drives due to differences in how Windows handles network paths.
Here are some troubleshooting steps you can try:
Use the UNC path instead of the mapped drive. Instead of using the mapped drive letter for the network attached drive, try using the UNC path instead. For example, instead of using
for /D %i in (X:\*) do echo %i
, try usingfor /D %i in (\\server\share\*) do echo %i
.Enable Linked Connections in Windows. Windows has a security feature called "Network security: Restrict NTLM: Outgoing NTLM traffic to remote servers" that can prevent network drives from being accessible in certain situations. To fix this issue, you can enable the "Linked Connections" policy in the Local Group Policy Editor. This can be done by following these steps:
a. Open the Local Group Policy Editor by running
gpedit.msc
in the Run dialog box.b. Go to Computer Configuration > Administrative Templates > System > Credentials Delegation.
c. Double-click the "Allow delegating fresh credentials with NTLM-only server authentication" policy.
d. Click the "Show" button.
e. Add "WSMAN/*" to the list of servers.
f. Click "OK" to close all the dialog boxes.
g. Restart your computer.
Use a different command. If the
for
command is still not working for network attached drives, you may need to use a different command that is designed to work with network paths. One such command isdir
, which can be used to list the contents of a folder on a network drive.
If none of these steps work, you may need to seek additional help or consult the Microsoft documentation for the for
command and network attached drives.