bsharath
asked on
Place all the files in a folder to all the relevant paths as per the file.
Hi,
I have a folder that has lots of files in a file.txt i have all the file paths.Is there a way to copy them to the relevant places checking the txt file.
\\machinename\C$\Program Files\Tivoli\TSM\console\s earch.avi
\\machinename\C$\WINNT\clo ck.avi
Regards
Sharath
I have a folder that has lots of files in a file.txt i have all the file paths.Is there a way to copy them to the relevant places checking the txt file.
\\machinename\C$\Program Files\Tivoli\TSM\console\s
\\machinename\C$\WINNT\clo
Regards
Sharath
ASKER
Rob i get this..
-------------------------- -
Windows Script Host
-------------------------- -
Script: C:\Place_all_files.vbs
Line: 11
Char: 7
Error: Type mismatch: 'Ping'
Code: 800A000D
Source: Microsoft VBScript runtime error
-------------------------- -
OK
-------------------------- -
Rob i need to do this from a remote machine.The script is running from a different machine not the machine name thats in the file.
--------------------------
Windows Script Host
--------------------------
Script: C:\Place_all_files.vbs
Line: 11
Char: 7
Error: Type mismatch: 'Ping'
Code: 800A000D
Source: Microsoft VBScript runtime error
--------------------------
OK
--------------------------
Rob i need to do this from a remote machine.The script is running from a different machine not the machine name thats in the file.
Oh yeah, I forgot the Ping function. Yeah, as long as you have the full path with \\machinename\c$\etc it should copy to it fine.
'=================
strSourceFolder = "C:\Temp\DistributionFiles "
strPlacementFile = "FileLocationsRequired.txt "
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strPla cementFile , intForReading, False)
While Not objInputFile.AtEndOfStream
strTarget = objInputFile.ReadLine
strFile = strSourceFolder & Mid(strTarget, InStr(strTarget, "\"))
strComputer = Replace(Left(strTarget, InStr(3, strTarget, "\")), "\", "")
If Ping(strComputer) = True Then
objFSO.CopyFile strFile, strTarget, True
Else
MsgBox "Cannot ping " & strComputer
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shel l")
boolCode = objShell.Run("Ping -n 4 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
'=================
Regards,
Rob.
'=================
strSourceFolder = "C:\Temp\DistributionFiles
strPlacementFile = "FileLocationsRequired.txt
Set objFSO = CreateObject("Scripting.Fi
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strPla
While Not objInputFile.AtEndOfStream
strTarget = objInputFile.ReadLine
strFile = strSourceFolder & Mid(strTarget, InStr(strTarget, "\"))
strComputer = Replace(Left(strTarget, InStr(3, strTarget, "\")), "\", "")
If Ping(strComputer) = True Then
objFSO.CopyFile strFile, strTarget, True
Else
MsgBox "Cannot ping " & strComputer
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shel
boolCode = objShell.Run("Ping -n 4 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
'=================
Regards,
Rob.
ASKER
Rob i get this...
-------------------------- -
Windows Script Host
-------------------------- -
Script: C:\Place_all_files.vbs
Line: 13
Char: 13
Error: Path not found
Code: 800A004C
Source: Microsoft VBScript runtime error
-------------------------- -
OK
-------------------------- -
Rob i used this batch file to move all found data
:: BATCH SCRIPT START
@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET NetShare=\\indiasophos\Ps
SET InputFile=Machines.txt
IF NOT EXIST "%NetShare%" ECHO Network share not found. &GOTO :EndScript
IF NOT EXIST "%InputFile%" ECHO "%InputFile%" file does not exist. &GOTO :EndScript
FOR %%R IN ("%InputFile%") DO IF %%~zR EQU 0 ECHO "%InputFile%" file is empty. &GOTO :EndScript
FOR /F %%c IN ('TYPE "%InputFile%"') DO (
ECHO Processing: %%c
IF NOT EXIST "!NetShare!\%%c" MD "!NetShare!\%%c"
IF EXIST FileList.txt DEL /F /Q FileList.txt
FOR /F "delims=: tokens=1" %%d IN ('WMIC /NODE:"%%c" LOGICALDISK WHERE "DriveType=3" GET Name ^|FIND ":"') DO (
DIR \\%%c\%%d$\*.mp3 /S /B 2>NUL >>FileList.txt
DIR \\%%c\%%d$\*.avi /S /B 2>NUL >>FileList.txt
DIR \\%%c\%%d$\*.mpg /S /B 2>NUL >>FileList.txt)
FOR /F "delims=*" %%f IN ('TYPE FileList.txt ^|FIND "\\"') DO MOVE /Y "%%f" "!NetShare!\%%c\" >NUL 2>&1
MOVE FileList.txt "!NetShare!\%%c\" >NUL 2>&1)
:EndScript
ENDLOCAL
EXIT /B 0
:: BATCH SCRIPT END
Hope this may help.Now i want to revert the copied files to its locations...
--------------------------
Windows Script Host
--------------------------
Script: C:\Place_all_files.vbs
Line: 13
Char: 13
Error: Path not found
Code: 800A004C
Source: Microsoft VBScript runtime error
--------------------------
OK
--------------------------
Rob i used this batch file to move all found data
:: BATCH SCRIPT START
@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET NetShare=\\indiasophos\Ps
SET InputFile=Machines.txt
IF NOT EXIST "%NetShare%" ECHO Network share not found. &GOTO :EndScript
IF NOT EXIST "%InputFile%" ECHO "%InputFile%" file does not exist. &GOTO :EndScript
FOR %%R IN ("%InputFile%") DO IF %%~zR EQU 0 ECHO "%InputFile%" file is empty. &GOTO :EndScript
FOR /F %%c IN ('TYPE "%InputFile%"') DO (
ECHO Processing: %%c
IF NOT EXIST "!NetShare!\%%c" MD "!NetShare!\%%c"
IF EXIST FileList.txt DEL /F /Q FileList.txt
FOR /F "delims=: tokens=1" %%d IN ('WMIC /NODE:"%%c" LOGICALDISK WHERE "DriveType=3" GET Name ^|FIND ":"') DO (
DIR \\%%c\%%d$\*.mp3 /S /B 2>NUL >>FileList.txt
DIR \\%%c\%%d$\*.avi /S /B 2>NUL >>FileList.txt
DIR \\%%c\%%d$\*.mpg /S /B 2>NUL >>FileList.txt)
FOR /F "delims=*" %%f IN ('TYPE FileList.txt ^|FIND "\\"') DO MOVE /Y "%%f" "!NetShare!\%%c\" >NUL 2>&1
MOVE FileList.txt "!NetShare!\%%c\" >NUL 2>&1)
:EndScript
ENDLOCAL
EXIT /B 0
:: BATCH SCRIPT END
Hope this may help.Now i want to revert the copied files to its locations...
OK, from what I understand, you have a folder with files in it, that you want to place into certain locations on remote computers. You have the required locations in a text file, and want to copy the files from your source folder to those locations. This should do that:
'======================
strSourceFolder = "C:\Temp\DistributionFiles "
strPlacementFile = "FileLocationsRequired.txt "
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strPla cementFile , intForReading, False)
While Not objInputFile.AtEndOfStream
strTarget = objInputFile.ReadLine
strFile = strSourceFolder & Mid(strTarget, InStrRev(strTarget, "\"))
strComputer = Replace(Left(strTarget, InStr(3, strTarget, "\")), "\", "")
If Ping(strComputer) = True Then
'MsgBox "Copying" & VbCrLf & strFile & VbCrLf & "to" & VbCrLf & strTarget & VbCrLf & "on " & strComputer
objFSO.CopyFile strFile, strTarget, True
Else
MsgBox "Cannot ping " & strComputer
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shel l")
boolCode = objShell.Run("Ping -n 4 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
'======================
Regards,
Rob.
'======================
strSourceFolder = "C:\Temp\DistributionFiles
strPlacementFile = "FileLocationsRequired.txt
Set objFSO = CreateObject("Scripting.Fi
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strPla
While Not objInputFile.AtEndOfStream
strTarget = objInputFile.ReadLine
strFile = strSourceFolder & Mid(strTarget, InStrRev(strTarget, "\"))
strComputer = Replace(Left(strTarget, InStr(3, strTarget, "\")), "\", "")
If Ping(strComputer) = True Then
'MsgBox "Copying" & VbCrLf & strFile & VbCrLf & "to" & VbCrLf & strTarget & VbCrLf & "on " & strComputer
objFSO.CopyFile strFile, strTarget, True
Else
MsgBox "Cannot ping " & strComputer
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shel
boolCode = objShell.Run("Ping -n 4 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
'======================
Regards,
Rob.
ASKER
Rob i even tried within the machine but still get this error.
permission denied error.
I think some files are copied.Can you have a results file on success and failure and even resume on error.please...
permission denied error.
I think some files are copied.Can you have a results file on success and failure and even resume on error.please...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Just waiting Rob its taking some time.Shall reply once done...
ASKER
Excellent Rob worked great,....
'===============
strSourceFolder = "C:\Temp\DistributionFiles
strPlacementFile = "FileLocationsRequired.txt
Set objFSO = CreateObject("Scripting.Fi
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strPla
While Not objInputFile.AtEndOfStream
strTarget = objInputFile.ReadLine
strFile = strSourceFolder & Mid(strTarget, InStr(strTarget, "\"))
strComputer = Replace(Left(strTarget, InStr(3, strTarget, "\")), "\", "")
If Ping(strComputer) = True Then
objFSO.CopyFile strFile, strTarget, True
Else
MsgBox "Cannot ping " & strComputer
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
'===============
Regards,
Rob.