Jump to content

Recommended Posts

Posted (edited)

Hello all,

 

 

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?

 

 

Thanks.

Edited by Robot
Posted

%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"

  • Thanks 1
Posted
%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.

Posted

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
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

  • Thanks 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...