Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Moving files from one directory to another based on the file namecontains specified string by using vbscript

Reply
 
Old 01-23-2009   #1 (permalink)
Sarvesh


 
 

Moving files from one directory to another based on the file namecontains specified string by using vbscript

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

My System SpecsSystem Spec
Old 01-25-2009   #2 (permalink)
Reventlov


 
 

Re: Moving files from one directory to another based on the file name contains specified string by using vbscript

Il giorno Fri, 23 Jan 2009 06:29:18 -0800 (PST), Sarvesh <sarveswara.p@xxxxxx> ha
scritto:
Quote:

>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.
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)
--
My System SpecsSystem Spec
Old 01-29-2009   #3 (permalink)
Sarvesh


 
 

Re: Moving files from one directory to another based on the file namecontains specified string by using vbscript

On Jan 26, 3:07*am, no...@xxxxxx (Reventlov) wrote:
Quote:

> Il giorno Fri, 23 Jan 2009 06:29:18 -0800 (PST), Sarvesh <sarveswar...@xxxxxx> ha
> scritto:
>
Quote:

> >Hi,
>
Quote:

> >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.
>
> This asks dos to write a file with the pathnames of all the files you arelooking 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 comhttp://digilander.libero.it/Cenati(Esempi 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
My System SpecsSystem Spec
Old 01-29-2009   #4 (permalink)
Pegasus \(MVP\)


 
 

Re: Moving files from one directory to another based on the file name contains specified string by using vbscript


"Sarvesh" <sarveswara.p@xxxxxx> wrote in message
news:b6d16742-0962-4466-ab65-755bb1f45b48@xxxxxx
Quote:

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


My System SpecsSystem Spec
Old 02-03-2009   #5 (permalink)
Sarvesh


 
 

Re: Moving files from one directory to another based on the file namecontains specified string by using vbscript

On Jan 29, 8:53*pm, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:
Quote:

> "Sarvesh" <sarveswar...@xxxxxx> wrote in message
>
> news:b6d16742-0962-4466-ab65-755bb1f45b48@xxxxxx
>
Quote:

> > Hi,
>
Quote:

> > 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.
>
Quote:

> > Thanks,
> > Sarvesh
>
> 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? Toa
> 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?
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
My System SpecsSystem Spec
Old 02-03-2009   #6 (permalink)
Pegasus \(MVP\)


 
 

Re: Moving files from one directory to another based on the file name contains specified string by using vbscript


"Sarvesh" <sarveswara.p@xxxxxx> wrote in message
news:f11127d0-3ab3-431a-b01c-caf3e270b89f@xxxxxx
On Jan 29, 8:53 pm, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:
Quote:

> "Sarvesh" <sarveswar...@xxxxxx> wrote in message
>
> news:b6d16742-0962-4466-ab65-755bb1f45b48@xxxxxx
>
Quote:

> > Hi,
>
Quote:

> > 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.
>
Quote:

> > Thanks,
> > Sarvesh
>
> 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?
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


My System SpecsSystem Spec
Old 02-11-2009   #7 (permalink)
Rahul


 
 

Re: Moving files from one directory to another based on the file n

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

>
> "Sarvesh" <sarveswara.p@xxxxxx> wrote in message
> news:f11127d0-3ab3-431a-b01c-caf3e270b89f@xxxxxx
> On Jan 29, 8:53 pm, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:
Quote:

> > "Sarvesh" <sarveswar...@xxxxxx> wrote in message
> >
> > news:b6d16742-0962-4466-ab65-755bb1f45b48@xxxxxx
> >
Quote:

> > > Hi,
> >
Quote:

> > > 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.
> >
Quote:

> > > Thanks,
> > > Sarvesh
> >
> > 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?
>
> 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
>
>
>
My System SpecsSystem Spec
Old 02-11-2009   #8 (permalink)
Rahul


 
 

RE: Moving files from one directory to another based on the file name

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

> 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
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: Moving files based on filesize PowerShell
Sample script to delete lines from a file based on a string PowerShell
Moving folders (including files) based to folder name PowerShell
Setting up a directory and moving a file into that directory from Vista General
Setting up a directory and moving a file into that directory from Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46