![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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. (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 Specs![]() |
| | #3 (permalink) |
| | 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) > -- 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 Specs![]() |
| | #4 (permalink) |
| | 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 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 Specs![]() |
| | #5 (permalink) |
| | 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? I am having the below code to move the files from one drive(c toanother(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 Specs![]() |
| | #6 (permalink) |
| | 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? I am having the below code to move the files from one drive(c toanother(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 Specs![]() |
| | #7 (permalink) |
| | 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 Specs![]() |
| | #8 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||