Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Batch file help needed

Featured Replies

for /D /R "%USERPROFILE%\Desktop" %%a IN ( * ) DO echo "%%a"

Using the command above, if there was a single folder on the Desktop named "backup", the (echo) command output would read:

"C:\>Documents and Settings\username\Desktop\backup"

My question is -- how do I extract the actual folder name itself so that it echoes "backup" instead of the full path?

Thanks in Advance.

This should give you the results you want...

for /D /R "%USERPROFILE%\Desktop" %%a IN ( * ) DO echo %%~na

Run FOR /? for a list of all the variable substitutions.

There are a multitude of ways of achieving the result you require!

Here's one:

FOR /F "DELIMS=" %%? IN ('DIR/B/AD "%USERPROFILE%\START MENU"') DO ECHO/%%?

[Edit]

Note I changed the name to Start Menu from Desktop in my example because there will always be at least one folder there for testing the code. The 'Desktop' on the other hand, I believe should only really contain links to objects, not the actual objects themselves.

[/Edit]

  • Author
Run FOR /? for a list of all the variable substitutions.

I have read over the variable substitutions many times and even spent hours on the net reading up on it... Just couldn't quite get the hang of it... A little to complicated for me I guess. Been doing a lot of batch scripting lately, so my brain is kinda out-of-sync atm... Interesting stuff nevertheless!

Thanks guys! Will give it a go.

Just couldn't quite get the hang of it.

Reference (with examples):

http://www.robvanderwoude.com/

http://www.robvanderwoude.com/ntfor.html

You can now use the following optional syntax:

%~i - expands %i removing any surrounding quotes (")

%~fi - expands %i to a fully qualified path name

%~di - expands %i to a drive letter only

%~pi - expands %i to a path only

%~ni - expands %i to a file name only

%~xi - expands %i to a file extension only

%~si - expanded path contains short names only

%~ai - expands %i to file attributes of file

%~ti - expands %i to date/time of file

%~zi - expands %i to size of file

%~$PATH:i - searches the directories listed in the PATH environment variable and expands %i to the fully qualified name of the first one found.

If the environment variable name is not defined or the file is not found by the search, then this modifier expands to the empty string

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

In the above examples %i and PATH can be replaced by other valid values.

Just be careful to pick your FOR variable letters to not conflict with any of the format specifier letters if you plan on using the enhanced substitution logic.

jaclaz

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.