Link to home
Start Free TrialLog in
Avatar of AXISHK
AXISHK

asked on

Dos script

for /F "tokens=1" %%I IN (list.txt) DO call D:\copyPC %%~nI


What's the meaning of adding ~n with the paramter %%I in the dos script ?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AXISHK
AXISHK

ASKER

Tks
Just to clarify...

You're using 'FOR /F "TOKENS=1" %%I IN (list.txt) DO...' so, you're assigning each line of text from the file 'list.txt' to the FOR-variable %%I.

So, if there are say, 6 lines of text in list.txt, your FOR-loop will execute the DO-part 6 times.

Assuming what's being assigned to %%I are filenames, whether or not they include the file's drive letter, path and/or extension, then the '~n' modifier will only assign the name-part to %%I - ignoring any drive letter, path and extension.

So, if the line 'C:\ABC.TXT' is read from the file list.txt then %%I will be set to just 'ABC' because you've specified you only want the name-part with the '~n' modifier.

Other related modifiers are:

~d         [d]rive letter (including the colon, ':')
~p         [p]path (including a leading and trailing forward slash '\')
~x         e[x]tension (including the fullstop '.')
~n         [n]ame
~f          [f]ull filename (including drive letter, path, name and extension)

Note: when using 'call d:\copypc %%~nI' it is always wiser to put %%I inside double-quotes ("...") just incase it contains spaces or other non-ordinary characters therefore, use the following instead:

for /f "tokens=1" %%I in (list.txt) do call D:\copyPC "%%~nI"

Open in new window

And remember to filter off the double-quotes in 'copyPC' using '%~1' rather than just '%1' if you need to.

I see points have already been awarded but no problem...