Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Anyone know a simple batch script that can list a directory of variable folders, then change to that variable? Example user names in documents and settings. The path to get into the user account folder you're logged into is %userprofile% is there anything like that for an account you arent logged into? if there isnt what would work to list and change to a variable dir?

Not clear what you want to do. You can list the other accts with this:
::== uu.bat
@echo off
setLocal EnableDelayedExpansionpushd "C:\Documents and Settings"
for /f "tokens=* delims= " %%a in ('dir /b/ad') do (
echo %%a
)
::==
=====================================
If at first you don't succeed, you're about average.M2

Basically in a batch file go into documents and settings, list and change to the foldernames. Folder names are always different because they are user accounts. So just need to list the user account folders in the batch file and change to that directory

Change to WHICH directory?
=====================================
If at first you don't succeed, you're about average.M2

to a variable directory.. like a profile name like John.. but if im not logged in as john how to i get the batch file to read the folder name & put me into that directory

cd /d "C:\Documents and Settings\John"
=====================================
If at first you don't succeed, you're about average.M2

no i mean like have the batch file do it.. but the name john is the variable its always different. say you have 5 folders in docs and settings. folder names nancy john tommy and alpha.. in the batch file without actually typing in any of those names.. how would i get the script to list them, then change to those dir's one at a time.. see what im trying to actually do is delete a file in appdata but the username is always different.. but without the full path(like john & sally) i cant

@echo off
setLocal EnableDelayedExpansionpushd "C:\Documents and Settings"
for /f "tokens=* delims= " %%a in ('dir /b/ad') do (
pushd "%%a\Application Data"
echo now we're in:
cd
echo and can do the delete
popd
)
popd
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |