NQMids
asked on
Complicted rename & move files
I'm trying to create a VBS script to do the following.
Copy PDF pages from CDROM to a temp location on local machine.
Rename the first two characters from what ever they may be to WR.
List all of the colour pages. (P = Colour M = Mono)
Show how many pages in total in publictaion.
Move pages to a UNC path.
Eject CDRom
Say the Job is complete.
Example file names
BM1AA080506M002.pdf (Mono Page)
BM1AA080506P001.pdf (Colour Page)
The BM tends to very a lot but needs to be renamed to WR.
As you can tell I’m not really a programmer. Here is what I have come up with so far.
All help gratefully received.
Please could you comment any work so I can learn and understand how it all works.
Many thanks in advance
'######################### ########## ########
'
' NAME: PageImport.vbs
'
' Date: 17/05/06
'
'######################### ########## #######
'Copies All PDF's From CD To Temp Loaction
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
objFSO.CopyFile "E:\*.pdf" , "D:\PDFTemp\" , OverwriteExisting
'Lists All Files In Temp Loaction
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper sonate}!\\ " & strComputer & "\root\cimv2")
Set colFiles = objWMIService. _
ExecQuery("Select * from CIM_DataFile where Path = '\\PDFTemp\\'")
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next
'Moves renamed Files into CTP System
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
objFSO.MoveFile "D:\PDFTemp\*.pdf" , "\\ms-wr-sysnas\Temp\"
'Eject CD ROM Drive
Const CDROM = 4
For Each d in CreateObject("Scripting.Fi leSystemOb ject").Dri ves
If d.DriveType = CDROM Then
Eject d.DriveLetter & ":\"
End If
Next
Sub Eject(CDROM)
Dim ssfDrives
ssfDrives = 17
CreateObject("Shell.Applic ation")_
.Namespace(ssfDrives).Pars eName(CDRO M).InvokeV erb("E&jec t")
End Sub
WScript.Echo "Page Import & Rename Finished."
Wscript.quit
Copy PDF pages from CDROM to a temp location on local machine.
Rename the first two characters from what ever they may be to WR.
List all of the colour pages. (P = Colour M = Mono)
Show how many pages in total in publictaion.
Move pages to a UNC path.
Eject CDRom
Say the Job is complete.
Example file names
BM1AA080506M002.pdf (Mono Page)
BM1AA080506P001.pdf (Colour Page)
The BM tends to very a lot but needs to be renamed to WR.
As you can tell I’m not really a programmer. Here is what I have come up with so far.
All help gratefully received.
Please could you comment any work so I can learn and understand how it all works.
Many thanks in advance
'#########################
'
' NAME: PageImport.vbs
'
' Date: 17/05/06
'
'#########################
'Copies All PDF's From CD To Temp Loaction
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.Fi
objFSO.CopyFile "E:\*.pdf" , "D:\PDFTemp\" , OverwriteExisting
'Lists All Files In Temp Loaction
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
Set colFiles = objWMIService. _
ExecQuery("Select * from CIM_DataFile where Path = '\\PDFTemp\\'")
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next
'Moves renamed Files into CTP System
Set objFSO = CreateObject("Scripting.Fi
objFSO.MoveFile "D:\PDFTemp\*.pdf" , "\\ms-wr-sysnas\Temp\"
'Eject CD ROM Drive
Const CDROM = 4
For Each d in CreateObject("Scripting.Fi
If d.DriveType = CDROM Then
Eject d.DriveLetter & ":\"
End If
Next
Sub Eject(CDROM)
Dim ssfDrives
ssfDrives = 17
CreateObject("Shell.Applic
.Namespace(ssfDrives).Pars
End Sub
WScript.Echo "Page Import & Rename Finished."
Wscript.quit
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nayer
I have just noticed the files are read only when they end up in the final location.
Is there away to stop this as it is causing problems.
Many Thanks
I have just noticed the files are read only when they end up in the final location.
Is there away to stop this as it is causing problems.
Many Thanks
You are welcome. :-)
As for your question, yes! Replace
__________________________ __________ __________
'List color pages and count the total number of pages
For Each pdffile in pdffiles
If Mid(pdffile.Name, 12, 1)="P" Then
Wscript.Echo pdffile.Name
End If
num=num+1
Next
'Display total number of pages
Wscript.Echo "Number of pages: " & num
__________________________ __________ __________
with
__________________________ __________ __________
Dim names
names=""
'Determine color pages and the total number of pages
For Each pdffile in pdffiles
If Mid(pdffile.Name, 12, 1)="P" Then
names=names & Chr(9) & pdffile.Name & Chr(10) & Chr(13)
End If
num=num+1
Next
'Display color pages and total number of pages
Wscript.Echo "Color pages: " & Chr(10) & Chr(13) & names
Wscript.Echo "Number of pages: " & num
__________________________ __________ __________
_______________
Nayer Naguib
As for your question, yes! Replace
__________________________
'List color pages and count the total number of pages
For Each pdffile in pdffiles
If Mid(pdffile.Name, 12, 1)="P" Then
Wscript.Echo pdffile.Name
End If
num=num+1
Next
'Display total number of pages
Wscript.Echo "Number of pages: " & num
__________________________
with
__________________________
Dim names
names=""
'Determine color pages and the total number of pages
For Each pdffile in pdffiles
If Mid(pdffile.Name, 12, 1)="P" Then
names=names & Chr(9) & pdffile.Name & Chr(10) & Chr(13)
End If
num=num+1
Next
'Display color pages and total number of pages
Wscript.Echo "Color pages: " & Chr(10) & Chr(13) & names
Wscript.Echo "Number of pages: " & num
__________________________
_______________
Nayer Naguib
Add the following after the line "num=num+1":
If (pdffile.Attributes And 1)=1 Then
pdffile.Attributes=pdffile .Attribute s - 1
End If
Or you can add the above lines to the body of the first "For Each" loop.
_______________
Nayer Naguib
If (pdffile.Attributes And 1)=1 Then
pdffile.Attributes=pdffile
End If
Or you can add the above lines to the body of the first "For Each" loop.
_______________
Nayer Naguib
ASKER
Thank you for the Colour page fix Nayer.
Any luck with the read only problem.
Many Thanks
Any luck with the read only problem.
Many Thanks
ASKER
Thank you for help Nayer.
Everything works perfect now.
Many Thanks again
Everything works perfect now.
Many Thanks again
ASKER
Thank you very much Nayer it worked a dream.
The file names will allways be the same length.
Many Thanks
Is it possible to list the colour pages in one window instead of individual windows.