search all drives for 'instances of

May 6, 2008 at 09:43:52
Specs: VISTA, Opteron 2x2Ghz and 2.5Gb

Hi, great site! Iv been helped a lot by this forum over the last week while putting together a batch file..this is 1 of the best batch sites iv found..of which there are thanks so far

I'v create a batch file to backup a 'user profile' folder that could exist in 4 different known locations on c:\(or it could be present in all 4 locations on c:\)

So far so good, The problem starts if the profile is located on an unknown drive or really struggling with this and indeed may be thinking the wrong way with needing 2 seperate batches

In thinking:
Create a second batch file which searches all drives for instances of the 'user profile' folder, then assigns the path of each profile found to a variable
2nd batch file would then edit the first batch, ie search and replace all known 'folder location data' with the new paths stored in the variables created

Its possible the user could have saved the profile to non default location, so just changing driver letters may not be enough

so to verify a 'found user profile':

Do all instances of file found (

If found(
"\Call of Duty 4 - Modern Warfare\players\profiles\active.txt"
then assign 'full path' to variable

any help would be appreciated

See More: search all drives for instances of

Report •

May 6, 2008 at 18:07:40

ok after botching some codes from around this forum I can now search all drives for a folder

Im sure this code is processing more than it needs to, how can i tweak the inner for loop
to search all drives/files(instead of only its own folder) removing the need for the outer for loop

@echo off
setLocal EnableDelayedExpansion

for %%d in (C D) do (
for /f "tokens=* delims= " %%a in ('dir/s/b/a-s \"Call of Duty 4 -

Modern Warfare"') do (
set var=%%~DPa
echo the path to profile directory is !var!


Report •

May 7, 2008 at 07:21:31

Remove the outer loop and replace the inner one with this:
for /f "tokens=* delims= " %%a in ('dir/s/b/a-s "C:\Call of Duty 4 - Modern Warfare" "D:\Call of Duty 4 - Modern Warfare"')

By the way, are you sure every PC has just a C: and a D: drive? What if it had an E: drive?

Report •

May 9, 2008 at 11:07:37


Report •

Related Solutions

May 9, 2008 at 13:34:18

Going loopy with this, basically I need a batch file to:

1)Start searching C: for folder called "players"
IF Found:
search the path of the folder(as a string) for string "VirtualStore" If True assign folder path to variable + "UAC ON"
search the folder path location for a
file called iw3mp.exe IF TRUE assign
folder path to variable + "UAC OFF"
ELSE Continue Searching Tthe Rest Of
The Drive
3)Repeat Until All available HD's have been searched D E F etc, with Found/Verified 'players folder' locations set to variables

The code below is to check for the "VirtualStore" string in the pathname ..but it complains of wrong syntax in the FOR statment...also I would need to create variables on the fly because the number of profiles that it could be found is unknown


FOR /f "tokens=* delims= " %%a IN ('dir/s/b/a-s "\players"') DO (

echo %playersLoc% | find "VirtualStore"

if errorlevel 1 goto :not-found

ECHO found
goto :end

ECHO not found



Report •

May 10, 2008 at 13:33:14

humpty bumpty

Report •

May 12, 2008 at 01:54:53

The command processor doesn't like the closing bracket coming straight after a label. If you add a statement (such as type nul) between :end and ")" then it will work.

What you're doing may be easier with VBScript, but I'm not an expert in that; others on this forum are.

Report •

Ask Question