chrischambers Posted April 27, 2009 Share Posted April 27, 2009 Hilooking through some of the posting I found the problem to one of my problems were I need to find and set a DocFolder Variable for My Documents as my users has there My Docs in different places.here is the code I found.@echo offset tagfile==%UserName%.txtecho %UserName%.txtfor %%d in (c d e f g h i j k l m n o p q r s t u v w x y z) do ( if exist %%d:\nul ( pushd "%%d:\" for /f "usebackq delims==" %%i in (`dir /s /b %tagfile% ^2^>nul`) do ( set docsfolder=%%i ) popd ))set docsfolder=%docsfolder:\chris.txt=%reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Personal /d "%docsfolder%" /f >nulecho %docsfolder%pause:goto :eofI have a little script that creates and place a txt file in each users my documents.this was in readiness for the migrating of Users to a new Computer. so I need to do is copy there profile details and My documents and place on a backup server. I am able to do find and backup the user’s desktop and Favourites from they profile, but when I use my New Variable %docsfolder% to locate and backup the users data. For some reason it is not finding the variable reference.here is my backup code.echo OffREM - FIRST MAKE SURE THAT THE TAGFILE PROGRAM IS RAN.REM - REM - this Batch file is to backup and zip all the users files from the localREM - machine and to place it onto a share folder on a serverREM -rem ** Map to a share locationnet use I: \\chris_laptop\mirgationrem - Create a User Folder on the server and local machinemkdir I:\users\%Username%mkdir c:\archiveREM copy pkzipc to the local machineREM copy I:\pkzipc.exe c:\REM - Zip the Default folders from the user profile and place then into the archive folderEcho Archiving %username% Profilepkzipc -add -silent -path=specify c:\archive\profile.zip "c:\%homepath%\desktop\*.*"pkzipc -add -silent -path=specify c:\archive\profile.zip "c:\%homepath%\favorites\*.*"Echo Archiving %username% MyDocumentsREM pkzipc -silent -add -path=specify c:\archive\profile.zip "c:\%commydocdir%\My Documents\*.*"REM pkzipc -silent -add -path=specify c:\archive\profile.zip "c:\%homepath%\My Documents\*.*"echo My Documents location - %docsfolder%pkzipc -silent -add -path=specify c:\archive\profile.zip "%docsfolder%\Convenandes\*.*"REM - check for other applicationIF not EXIST "C:\Lotus\Notes\ah7lena.dat" goto ENDNOTES Echo Archving Lotus Notes pkzipc -add -silent -path=specify c:\archive\notes.zip "c:\lotus\notes\*.*"goto end:ENDNOTES Echo Not a Lotus Notes UsersREM Put more If statements here:endREM - Copy all the files from the C:\archiveecho Moving files to Archive Folderxcopy c:\archive\*.* I:\users\%Username% /e/i/y/r/kREM - BACKUP COMPLETEecho Archving of all user information is complatedREM - clean up hard drive rmdir c:\archive /s /qpauseCan anyone see why this is not working. ? Link to comment Share on other sites More sharing options...
IcemanND Posted April 27, 2009 Share Posted April 27, 2009 First thing I see is this:set docsfolder=%docsfolder:\chris.txt=%If you are after setting dodsfolder to say c:\chris.txt it should beset docsfolder=%docsfolder%:\chris.txtother wise it will stay being just the drive letter.Second I believe the way you are setting the environment variable, by adding it to the registry requires a reboot before it is available in any applications or command windows other than the original window it was created in. Link to comment Share on other sites More sharing options...
Yzöwl Posted April 27, 2009 Share Posted April 27, 2009 If you want to set three variables for the Favorites, Desktop and My Documents locations, they can be taken directly from the registry:Example.cmd@Echo off&SetlocalSet K_="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"For /f "tokens=1,2*" %%a In ( 'Reg query %K_%^|Findstr/i "Desktop Personal Favorites"') Do (Set %%a="%%c")Echo/%%Desktop%%=%Desktop%Echo/%%Personal%%=%Personal%Echo/%%Favorites%%=%Favorites%Pause Link to comment Share on other sites More sharing options...
chrischambers Posted April 27, 2009 Author Share Posted April 27, 2009 First thing I see is this:set docsfolder=%docsfolder:\chris.txt=%If you are after setting dodsfolder to say c:\chris.txt it should beset docsfolder=%docsfolder%:\chris.txtother wise it will stay being just the drive letter.Second I believe the way you are setting the environment variable, by adding it to the registry requires a reboot before it is available in any applications or command windows other than the original window it was created in.I think that you might have miss read the code, set docsfolder=%docsfolder%:\chris.txt - is setting the docsfolder to the path of the "My documents" as this folders has different locationsregarding setting up the Variables for Desktop and Fav, this I don't want to do, as this code is only backing up and zipping up the folders in readiness for transfer. Link to comment Share on other sites More sharing options...
Yzöwl Posted April 27, 2009 Share Posted April 27, 2009 I know you've already got code which finds the Favorites and Desktop directories and they very likely suit your system, however those locations may also be redirected in the same way as you state that some of the My Documents locations are. The code I provided was simply an example for others to locate all three locations at once.Doing a full directory and subdirectory search for a particular text file under every drive on the PC is not the most efficient system for doing your task and the code you found is not very good at that either!@Echo offSetlocalSet K_="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"For /f %%a in ('Mountvol^|Findstr [c-z]:\\') Do Call :Chkit %%aPause&Goto :Eof:ChkitFor /f "delims=" %%a In ( 'Dir/b/s/a-d %1%UserName%.txt 2^>Nul') Do Call :Addit %%~dpaGoto :Eof:AdditSet P_=%*Reg add %K_% /v Personal /d "%P_:~,-1%" /f>NulYou backup code is using variables which have not been set or are set incorrectly.%docsfolder% has not been set and therefore has no value%HomePath% already has a (built-in) leading backslash meaning that you've doubled it up. It would also be better implemented with %HomeDrive%, (as %HOMEDRIVE%%HOMEPATH%), however the standard %USERPROFILE% should suffice. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now