Copying files off PCs
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?
%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"
I would be wanting to run it remotely but only to select PCs in the domain, so would also need to target them somehow.
Originally Posted by OutToLunch
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.
'what's the folder to look for
'where do you want it copying to
'simple list of PCs; read it and store in array
do while not oFile.atendofstream
iComputers=iComputers + 1
redim preserve sComputers(iComputers)
for each sComputer in sComputers
if sComputer<>"" then
'get the root of D&S
sPath="\\" & sComputer & "\c$\documents and settings\"
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
ofso.copyfolder sPath & oSubFolder.Name & "\" & sFolderName,sDestination & sComputer & "\" & oSubFolder.Name & "\"
Thanks very much! I will have a look at this on Monday :D