From: sweta Rai on
I have a code which would copy a file from a location to another, make 2 copies of it and rename both.But when i try to rename, it is renaming the file at source folder. Pls suggest

Sub mycode()
Dim filesys, oFile, sName, oCount, dFile
'Set oCount = 0
Const sSourceFdr = "E:\VBS\"
Const sDestFdr = "E:\VBS\temp\"
Set filesys = CreateObject("Scripting.FileSystemObject")

For Each oFile In filesys.GetFolder(sSourceFdr).Files
On Error Resume Next
If InStr(1, oFile.Name, "Actuals") <> 0 Then

filesys.CopyFile oFile.Path, sDestFdr, OverWriteExisting


sName = Replace(oFile.Name, "Inter", "InterCA")
oFile.Name = sName
End If
Next
On Error GoTo 0

End Sub

> On Sunday, January 25, 2009 1:04 AM Sarvesh wrote:

> Hi,
>
> I am having different kind of files need to move from one drive to
> another based on the file name contains specified string by using
> vbscript. For example, i need to move the file that the filename
> contains string "mylog". Please help me to write vbscript to do this
> job.
>
> Thanks,
> Sarvesh


>> On Sunday, January 25, 2009 5:07 PM noon wrote:

>> Il giorno Fri, 23 Jan 2009 06:29:18 -0800 (PST), Sarvesh <sarveswara.p(a)gmail.com> ha
>> scritto:
>>
>>
>> This asks dos to write a file with the pathnames of all the files you are looking for
>> (maybe).
>>
>> drive="c:\"
>> cmd = "dir "& trim(drive) & "*mylog* /s/b "
>> tmp = "c:\data\pathnames.txt"
>> Set WshShell = CreateObject("WScript.Shell")
>> WSHShell.Run "%comspec% /c " & cmd & " >" & tmp, 0, True
>>
>>
>> --
>> Giovanni Cenati (Bergamo, Italy)
>> Write to "Reventlov" at katamail com
>> http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
>> --


>>> On Thursday, January 29, 2009 10:53 AM Pegasus \(MVP\) wrote:

>>> "Sarvesh" <sarveswara.p(a)gmail.com> wrote in message
>>> news:b6d16742-0962-4466-ab65-755bb1f45b48(a)41g2000yqf.googlegroups.com...
>>>
>>> You need to think about your requirements in more detail and post the
>>> following information:
>>> - Where are your files kept? In a single folder? In a directory tree?
>>> - Where do you want to move them to? To the root of another partition? To a
>>> folder on that partition? If so, what name? Do you wish to rebuild the
>>> source directory tree on the target partition?
>>> - What should happen if a file of the same name already exists on the target
>>> partition?
>>> - Can you show us the (partial) script solution you have developed so far?


>>>> On Saturday, January 31, 2009 11:38 PM Sarvesh wrote:

>>>> On Jan 26, 3:07=A0am, no...(a)no.void (Reventlov) wrote:
>>>> ail.com> ha
>>>> looking for
>>>> empi e programmi in VbScript)
>>>>
>>>> Hi,
>>>>
>>>> The above mentioned code is not moving any files. It is just creating
>>>> pathnames.txt file. I need to move the files that those filenames
>>>> contains string "mylog".
>>>>
>>>> Please help me to get the appropriate code.
>>>>
>>>> Thanks in Advance.
>>>>
>>>> Regards,
>>>> Sarvesh


>>>>> On Tuesday, February 03, 2009 8:41 AM Pegasus \(MVP\) wrote:

>>>>> "Sarvesh" <sarveswara.p(a)gmail.com> wrote in message
>>>>> news:f11127d0-3ab3-431a-b01c-caf3e270b89f(a)s20g2000yqh.googlegroups.com...
>>>>> On Jan 29, 8:53 pm, "Pegasus \(MVP\)" <I....(a)fly.com.oz> wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I am having the below code to move the files from one drive(c:) to
>>>>> another(d:).
>>>>>
>>>>> Option Explicit
>>>>>
>>>>> Dim oFS, oFile, sFile
>>>>>
>>>>> Set oFS = WScript.CreateObject("Scripting.FileSystemObject")
>>>>>
>>>>> Const sSourceFdr = "C:\test1\"
>>>>> Const sDestFdr = "D:\test2\"
>>>>> Const nDays = 10
>>>>>
>>>>> For Each oFile In oFS.GetFolder(sSourceFdr).Files
>>>>> On Error Resume Next
>>>>> If DateDiff("d", oFile.DateLastModified, Now) > nDays Then
>>>>> oFS.MoveFile oFile.Path, sDestFdr
>>>>> End If
>>>>> On Error Goto 0
>>>>> Next
>>>>> Set oFS = Nothing
>>>>> WScript.Quit
>>>>>
>>>>> I need cut and paste the files those filename's contains "mylog" .
>>>>>
>>>>> Thanks,
>>>>> Sarvesh
>>>>>
>>>>> ==================
>>>>>
>>>>> You can introduce an overall "if" condition like so:
>>>>> if instr(1, oFile.Name, "mylog", 1) > 0 then
>>>>> {do your file move}
>>>>> end if


>>>>>> On Wednesday, February 04, 2009 5:17 AM Sarvesh wrote:

>>>>>> On Jan 29, 8:53=A0pm, "Pegasus \(MVP\)" <I....(a)fly.com.oz> wrote:
>>>>>> a
>>>>>> get
>>>>>> ?
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I am having the below code to move the files from one drive(c:) to
>>>>>> another(d:).
>>>>>>
>>>>>> Option Explicit
>>>>>>
>>>>>> Dim oFS, oFile, sFile
>>>>>>
>>>>>> Set oFS =3D WScript.CreateObject("Scripting.FileSystemObject")
>>>>>>
>>>>>> Const sSourceFdr =3D "C:\test1\"
>>>>>> Const sDestFdr =3D "D:\test2\"
>>>>>> Const nDays =3D 10
>>>>>>
>>>>>> For Each oFile In oFS.GetFolder(sSourceFdr).Files
>>>>>> On Error Resume Next
>>>>>> If DateDiff("d", oFile.DateLastModified, Now) > nDays Then
>>>>>> oFS.MoveFile oFile.Path, sDestFdr
>>>>>> End If
>>>>>> On Error Goto 0
>>>>>> Next
>>>>>> Set oFS =3D Nothing
>>>>>> WScript.Quit
>>>>>>
>>>>>> I need cut and paste the files those filename's contains "mylog" .
>>>>>>
>>>>>> Thanks,
>>>>>> Sarvesh


>>>>>>> On Wednesday, February 11, 2009 3:59 AM Rahu wrote:

>>>>>>> Hi Sarvesh,
>>>>>>>
>>>>>>> Try the below script...
>>>>>>>
>>>>>>> Dim sOriginFolder, sDestinationFolder, sFile, oFSO
>>>>>>> Set oFSO = CreateObject("Scripting.FileSystemObject")
>>>>>>> sOriginFolder = "D:\Documents\P2P Dev\BoA_H2H\XML\"
>>>>>>> sDestinationFolder = "D:\Documents\P2P Dev\BoA_H2H\XML\TrasnferXML\"
>>>>>>> For Each sFile In oFSO.GetFolder(sOriginFolder).Files
>>>>>>> If instr(1, sFile.Name, ".xml", 1) > 0 then
>>>>>>> oFSO.MoveFile sFile, sDestinationFolder
>>>>>>> End If
>>>>>>>
>>>>>>> Next
>>>>>>>
>>>>>>>
>>>>>>> I am pretty sure this will work for you.
>>>>>>>
>>>>>>> Thanks
>>>>>>> Rahul
>>>>>>>
>>>>>>> "Pegasus (MVP)" wrote:


>>>>>>>> On Wednesday, February 11, 2009 4:00 AM Rahul_Bangi wrote:

>>>>>>>> Hi Sarvesh,
>>>>>>>>
>>>>>>>> Try this....
>>>>>>>>
>>>>>>>> Dim sOriginFolder, sDestinationFolder, sFile, oFSO
>>>>>>>> Set oFSO = CreateObject("Scripting.FileSystemObject")
>>>>>>>> sOriginFolder = "D:\Documents\P2P Dev\BoA_H2H\XML\"
>>>>>>>> sDestinationFolder = "D:\Documents\P2P Dev\BoA_H2H\XML\TrasnferXML\"
>>>>>>>> For Each sFile In oFSO.GetFolder(sOriginFolder).Files
>>>>>>>> If instr(1, sFile.Name, ".xml", 1) > 0 then
>>>>>>>> oFSO.MoveFile sFile, sDestinationFolder
>>>>>>>> End If
>>>>>>>>
>>>>>>>> Next
>>>>>>>>
>>>>>>>>
>>>>>>>> I am pretty sure it will work for you.
>>>>>>>>
>>>>>>>> Thanks
>>>>>>>> Rahul
>>>>>>>>
>>>>>>>> "Sarvesh" wrote:


>>>>>>>> Submitted via EggHeadCafe - Software Developer Portal of Choice
>>>>>>>> ASP.NET HttpPostedFile Image Resizer
>>>>>>>> http://www.eggheadcafe.com/tutorials/aspnet/ba8d2418-6d67-40f7-989c-e90688058778/aspnet-httppostedfile-image-resizer.aspx
From: "Dave "Crash" Dummy" on
sweta Rai wrote:
> I have a code which would copy a file from a location to another, make 2 copies of it and rename both.But when i try to rename, it is renaming the file at source folder. Pls suggest
>
> Sub mycode()
> Dim filesys, oFile, sName, oCount, dFile
> 'Set oCount = 0
> Const sSourceFdr = "E:\VBS\"
> Const sDestFdr = "E:\VBS\temp\"
> Set filesys = CreateObject("Scripting.FileSystemObject")
>
> For Each oFile In filesys.GetFolder(sSourceFdr).Files
> On Error Resume Next
> If InStr(1, oFile.Name, "Actuals") <> 0 Then
>
> filesys.CopyFile oFile.Path, sDestFdr, OverWriteExisting
>
>
> sName = Replace(oFile.Name, "Inter", "InterCA")
> oFile.Name = sName
> End If
> Next
> On Error GoTo 0
>
> End Sub

Replace your IF...END IF code segment with this:

If InStr(1, oFile.Name, "Actuals") <> 0 Then
sName = Replace(oFile.Name, "Inter", "InterCA")
oFile.copy sDestFdr & sName
End If

--
Crash

"Facts are stubborn things, but statistics are more pliable."
~ Laurence J. Peter ~
From: Todd Vargo on
sweta Rai wrote:
> I have a code which would copy a file from a location to another, make
> 2 copies of it and rename both.But when i try to rename, it is renaming
> the file at source folder. Pls suggest
>
> Sub mycode()
> Dim filesys, oFile, sName, oCount, dFile
> 'Set oCount = 0
> Const sSourceFdr = "E:\VBS\"
> Const sDestFdr = "E:\VBS\temp\"
> Set filesys = CreateObject("Scripting.FileSystemObject")
>
> For Each oFile In filesys.GetFolder(sSourceFdr).Files
> On Error Resume Next
> If InStr(1, oFile.Name, "Actuals") <> 0 Then
>
> filesys.CopyFile oFile.Path, sDestFdr, OverWriteExisting

Your code does not set OverWriteExisting as a constant or variable.

>
>
> sName = Replace(oFile.Name, "Inter", "InterCA")
> oFile.Name = sName
^^^^^^^^^^
You have the code set to rename the source file above.


> End If
> Next
> On Error GoTo 0
>
> End Sub

The code does not make 2 copies as you mentioned and you are not clear on
what you want. I can not tell if you really wanted to create two copies with
different names but ISTM, best to just copy directly to the new name and
omit the rename process.

Sub mycode()
Dim filesys, oFile, sName
Const sSourceFdr = "E:\VBS\"
Const sDestFdr = "E:\VBS\temp\"
Const OverWriteExisting = True
Set filesys = CreateObject("Scripting.FileSystemObject")

'On Error Resume Next
For Each oFile In filesys.GetFolder(sSourceFdr).Files
If InStr(1, oFile.Name, "Actuals") <> 0 Then
sName = Replace(oFile.Name, "Inter", "InterCA")
filesys.CopyFile oFile.Path, sDestFdr & sName, OverWriteExisting
End If
Next
On Error GoTo 0
End Sub

From: Todd Vargo on
Dave "Crash" Dummy wrote:
> sweta Rai wrote:
>> I have a code which would copy a file from a location to another, make 2
>> copies of it and rename both.But when i try to rename, it is renaming the
>> file at source folder. Pls suggest
>>
>> Sub mycode()
>> Dim filesys, oFile, sName, oCount, dFile
>> 'Set oCount = 0
>> Const sSourceFdr = "E:\VBS\"
>> Const sDestFdr = "E:\VBS\temp\"
>> Set filesys = CreateObject("Scripting.FileSystemObject")
>>
>> For Each oFile In filesys.GetFolder(sSourceFdr).Files
>> On Error Resume Next
>> If InStr(1, oFile.Name, "Actuals") <> 0 Then
>>
>> filesys.CopyFile oFile.Path, sDestFdr, OverWriteExisting
>> sName = Replace(oFile.Name, "Inter", "InterCA")
>> oFile.Name = sName
>> End If
>> Next
>> On Error GoTo 0
>>
>> End Sub
>
> Replace your IF...END IF code segment with this:
>
> If InStr(1, oFile.Name, "Actuals") <> 0 Then
> sName = Replace(oFile.Name, "Inter", "InterCA")
> oFile.copy sDestFdr & sName
> End If

Cool, oFile.copy overwrites without a blink.

--
Todd Vargo

(Post questions to group only. Remove "z" to email personal messages)

 | 
Pages: 1
Prev: Help with writing a script
Next: Calling a C++ dll