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

Reply
 
Old 4 Weeks Ago   #1 (permalink)
Doug Howell


 
 

moving files.....

I need a script that will check a given directory for .pdf and .xls
files that have exactly the same name. If a pair of .pdf and .xls
files with the same name are found, the script should move the .xls
file to another directory.

Any guidance would be appreciated.

My System SpecsSystem Spec
Old 4 Weeks Ago   #2 (permalink)
Pegasus [MVP]


 
 

Re: moving files.....


"Doug Howell" <douglasehowell@newsgroup> wrote in message
news:a8b0c282-0785-4a2e-8929-b6fe25bbebcf@newsgroup
Quote:

>I need a script that will check a given directory for .pdf and .xls
> files that have exactly the same name. If a pair of .pdf and .xls
> files with the same name are found, the script should move the .xls
> file to another directory.
>
> Any guidance would be appreciated.
You posted exactly the same question last Friday in the Scripting.wsh
newsgroup. Did you try the suggestion that you received?


My System SpecsSystem Spec
Old 4 Weeks Ago   #3 (permalink)
ekkehard.horner


 
 

Re: moving files.....

Doug Howell schrieb:
Quote:

> I need a script that will check a given directory for .pdf and .xls
> files that have exactly the same name. If a pair of .pdf and .xls
> files with the same name are found, the script should move the .xls
> file to another directory.
>
> Any guidance would be appreciated.
Given this folder tree:

+---dst
\---src
F0001.pdf
F0001.xls (b)
F0002.xls
F0003.pdf
F0004.txt
F0005.pdf
F0005.xls (b)
F0006.xls
F0007.pdf
F0008.txt
F0009.pdf
F0009.xls (b)
F0010.xls

with 3 .XLSs that have .PDF 'brothers', this code:

Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim sSDir : sSDir = ".\movebrothers\src"
Dim sDDir : sDDir = ".\movebrothers\dst"
' Loop over all files in sSDir
Dim oFile
For Each oFile In oFS.GetFolder( sSDir ).Files
If "XLS" = UCase( oFS.GetExtensionName( oFile.Name ) ) Then ' found .xls
Dim sBro : sBro = sSDir & "\" & oFS.GetBaseName( oFile.Path ) & ".pdf"
If oFS.FileExists( sBro ) Then ' found brother
Dim sDst : sDst = sDDir & "\" & oFile.Name
oFile.Move sDst
End If
End If
Next

will result in:

+---dst
| F0001.xls
| F0005.xls
| F0009.xls
|
\---src
F0001.pdf
F0002.xls
F0003.pdf
F0004.txt
F0005.pdf
F0006.xls
F0007.pdf
F0008.txt
F0009.pdf
F0010.xls
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Moving files Microsoft Office
moving files Vista General
Moving Files Vista performance & maintenance
Moving files Vista file management
moving files General Discussion


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