CalmSoul
asked on
batch script help
Hello Experts:
I am looking for simple VB script to read file path from file1.txt and copy each of them (files) to different folder on the network
Does anybody has anything they can share?
I am looking for simple VB script to read file path from file1.txt and copy each of them (files) to different folder on the network
Does anybody has anything they can share?
If he really wants VBS, then...
' Copy files in a list to a folder
Const OverwriteExisting = TRUE
Const ForReading = 1
sTgtPath="\\server\share\"
sSrcPath="c:\dir\file1.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
(sSrcPath, ForReading)
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arrServiceList = Split(strNextLine , ",")
Wscript.Echo "Copying " & strNextLine & " to " & sTgtPath
objFSO.CopyFile strNextLine , sTgtPath, OverwriteExisting
Loop
ASKER
Will it be possible to have output logs what got copied?
This will add some logging to the file specified.
@echo off
setlocal
set DestDir=H:\destdir
set FileList=file1.txt
set LogFile=copylog.txt
echo Started: %DATE% %TIME%>>"%LogFile%"
for /f "tokens=* usebackq" %%A in ("%FileList%") do (
echo Copying: "%%~A" to "%%~A">>"%LogFile%"
copy "%%~A" "%%~A"
)
echo Ended: %DATE% %TIME%>>"%LogFile%"
~bp
VBS. Added logging.
' Copy files in a list to a folder
Const OverwriteExisting = TRUE
Const ForReading = 1, ForWriting = 2, ForAppending = 8
sTgtPath="\\server\share\"
sSrcPath="c:\dir\file1.txt"
sLog="%temp%\copyfilesLog.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set obSrcFN = objFSO.OpenTextFile (sSrcPath, ForReading)
Set obLogFN = objFSO.OpenTextFile (sLog, ForAppending, True)
Do Until obSrcFN.AtEndOfStream
strNextLine = obSrcFN.Readline
arrServiceList = Split(strNextLine , ",")
Wscript.Echo Now & " " & "Copying " & strNextLine & " to " & sTgtPath
objFSO.CopyFile strNextLine , sTgtPath, OverwriteExisting
obLogFN.WriteLine Now & " " & strNextLine
Loop
@NVIT,
I think you forgot the close of the log file, which is critical.
~bp
I think you forgot the close of the log file, which is critical.
~bp
' Copy files in a list to a folder
Const OverwriteExisting = TRUE
Const ForReading = 1, ForWriting = 2, ForAppending = 8
sTgtPath="\\server\share\"
sSrcPath="c:\dir\file1.txt"
sLog="c:\dir\copyfilesLog.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set obSrcFN = objFSO.OpenTextFile (sSrcPath, ForReading)
Set obLogFN = objFSO.OpenTextFile (sLog, ForAppending, True)
Do Until obSrcFN.AtEndOfStream
strNextLine = obSrcFN.Readline
arrServiceList = Split(strNextLine , ",")
Wscript.Echo Now & " " & "Copying " & strNextLine & " to " & sTgtPath
objFSO.CopyFile strNextLine , sTgtPath, OverwriteExisting
obLogFN.WriteLine Now & " " & strNextLine
Loop
obSrcFN.Close
obLogFN.Close
ASKER
@NewVillageIT (NVIT) - on your script I am getting error permission denied
C:\temp\readncopy.vbs(19, 5) Microsoft VBScript runtime error: Permission denied
ASKER
@Bill Prew - on your batch file ...
nothing get copys.. and when I looked at the logs it was copying from target to target
nothing get copys.. and when I looked at the logs it was copying from target to target
@CalmSoul
Do you have copy rights to sTgtPath? Can you confirm by creating a file manually there?
Do you have copy rights to sTgtPath? Can you confirm by creating a file manually there?
ASKER
@NewVillageIT (NVIT) - yes, I can create file manually
ASKER
I even added everyone with full control on that folder ...
Can you change sTgtPath temporarily, to a local folder that also has write rights? Then test. e.g.
sTgtPath="c:\testfolder\"
ASKER
the folder I am copying in is local folder to my machine
@CalmSoul,
What folder did you run the batch script from?
Can you paste up a few lines from the output log?
~bp
@Bill Prew - on your batch file ...What do the lines in your text file look like, full path, or just a file name?
nothing get copys.. and when I looked at the logs it was copying from target to target
What folder did you run the batch script from?
Can you paste up a few lines from the output log?
~bp
@CalmSoul,
I don't get an error here. Can you post a sample of your sSrcPath file?
I don't get an error here. Can you post a sample of your sSrcPath file?
ASKER
Bill- I was able to fix your script and got it working now... Question will it be possible to capture instance file not exist in different log file..
I want to capture file path.. Thanks
I want to capture file path.. Thanks
@CalmSoul,
I don't understand the question you are now asking, can you explain further please.
~bp
I don't understand the question you are now asking, can you explain further please.
~bp
ASKER
@Bill: During the copy process, if source file doesn't exist .. I get output "file not found" or something.. Is it possible to track that output in separate log file ...
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Open in new window
~bp