For loop to hit each user on a machine

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
motanicus
Posts: 19
Joined: 26 Mar 2013 11:13

Re: For loop to hit each user on a machine

#31 Post by motanicus » 26 Mar 2013 19:27

foxidrive wrote:This was convoluted - I think I got it right. It removes the \users\username\

Code: Select all

@echo off
for %%a in ("%userprofile%") do (
for /f "delims=" %%b in ('dir "%%~dpa" /ad /b') do (
pushd "%%~dpa\%%b"
for /f "delims=" %%c in ('dir *.ost *.pst  /a-d /b /s 2^>nul ') do (
call :next "%%~dpa%%b" "%%~dpc" "%%c"
)
popd
)
)
pause
goto :EOF

:next
set "var1=%~1"
set "var2=%~2"
call set "var3=%%var2:%var1%=%%"
md "%~1\AppData\Local\Microsoft\Outlook\Backup\%var3%" 2>nul
move "%~3" "%~1\AppData\Local\Microsoft\Outlook\Backup\%var3%" >nul


Awesome, I will check this out tomorrow on my test box and let ya know if it works out.
thanks!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: For loop to hit each user on a machine

#32 Post by foxidrive » 26 Mar 2013 21:19

Just so you are aware, that version actually moves the files.

This version should create and move the temp files.

Code: Select all

@echo off
for %%a in ("%userprofile%") do (
for /f "delims=" %%b in ('dir "%%~dpa" /ad /b') do (
pushd "%%~dpa\%%b"
for /f "delims=" %%c in ('dir *.ost *.pst  /a-d /b /s 2^>nul ') do (
call :next "%%~dpa%%b" "%%~dpc" "%%c"
)
popd
)
)
pause
goto :EOF

:next
set "var1=%~1"
set "var2=%~2"
call set "var3=%%var2:%var1%=%%"
type nul> "%~3.movetest"
md "%~1\AppData\Local\Microsoft\Outlook\Backup\%var3%" 2>nul
move "%~3.movetest" "%~1\AppData\Local\Microsoft\Outlook\Backup\%var3%" >nul


motanicus
Posts: 19
Joined: 26 Mar 2013 11:13

Re: For loop to hit each user on a machine

#33 Post by motanicus » 27 Mar 2013 09:45

ha one more funky thing:
C:\Users\username\AppData\Local\Microsoft\Outlook\Backup\AppData\Local\Microsoft\Outlook\Backup\AppData\Local\Microsoft\Outlook
is now the new backup location
otherwise this is working perfectly (removes the OST/PST file from original source)
Last edited by motanicus on 15 Dec 2023 18:11, edited 1 time in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: For loop to hit each user on a machine

#34 Post by foxidrive » 27 Mar 2013 16:29

motanicus wrote:ha one more funky thing:
C:\Users\thoopes\AppData\Local\Microsoft\Outlook\Backup\AppData\Local\Microsoft\Outlook\Backup\AppData\Local\Microsoft\Outlook
is now the new backup location
otherwise this is working perfectly (removes the OST/PST file from original source)


It doesn't use that location here. Try removing all files/folders from here and running it again.
C:\Users\thoopes\AppData\Local\Microsoft\Outlook\Backup


EDIT: Maybe if an earlier folder contained some backups then it will move them again.

Post Reply