I need to copy a specific folder off a number of different PCs. I would like to do this via a script if possible.
The only problem I can see is that the folder is in
C:\documents and settings\user name\...rest of string...
How would I write something that gets me through that "user name" folder into the directory below, regardless of what that "user name" folder is named?
Last edited by Robot; 19th March 2010 at 03:55 PM.
%username% returns the logged on username though, it won't walk through directories in the documents and settings folder. Are you going to be running the script manually at each PC or do you want to do it remotely?
You'll want something like a for loop in the script to walk through the directories -
cd C:\documents and settings\
for %%I /D in (*) do copy "C:\documents and settings\%%I\yourstring\yourfile.txt" "\\server\folder"
Robot (19th March 2010)
something like this? Not sure if you have a known list of PCs (this assumes you have an it's in a plain text file) or if you're going to query all PCs in an OU in AD or whatever but I hope this gets you started.
Code:'what's the folder to look for sFolderName="Application Data\Maple\13" 'where do you want it copying to sDestination="\\cs-srochfor-01\tmp\" dim sComputers() dim iComputers icomputers=0 set oFSO=createobject("scripting.filesystemobject") GetComputerList QueryComputers sub GetComputerList 'simple list of PCs; read it and store in array sList="c:\temp\pcs.txt" set oFile=ofso.opentextfile(sList) do while not oFile.atendofstream sComputer=oFile.readline iComputers=iComputers + 1 redim preserve sComputers(iComputers) sComputers(iComputers)=sComputer loop oFile.close end sub sub QueryComputers for each sComputer in sComputers if sComputer<>"" then 'get the root of D&S sPath="\\" & sComputer & "\c$\documents and settings\" set oFolder=ofso.getfolder(sPath) for each oSubFolder in oFolder.subfolders 'look at each user folder if ofso.folderexists(sPath & oSubFolder.Name & "\" & sFolderName) then 'the folder we want exists so make a suitable folder on the destination machine - first for computer if not ofso.folderexists(sDestination & sComputer) then ofso.createfolder sDestination & sComputer 'and now for user if not ofso.folderexists(sDestination & sComputer & "\" & oSubFolder.Name) then ofso.createfolder sDestination & sComputer & "\" & oSubFolder.Name 'copy everything ofso.copyfolder sPath & oSubFolder.Name & "\" & sFolderName,sDestination & sComputer & "\" & oSubFolder.Name & "\" end if next end if next end sub
Robot (21st March 2010)
Thanks very much! I will have a look at this on Monday
There are currently 1 users browsing this thread. (0 members and 1 guests)