Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move all *.pdf files from a folder 1

Status
Not open for further replies.

JV28132

Programmer
Apr 19, 2010
11
US
I have this script that will move all *.pdf files from a folder to a specific location. The script is as follows: It executes on Load and I can get it to work via Visual studio editor (stepping through) but when the vbscript runs, it does not work.. If anyone can understand why, please please forward your thoughts. Thanks,


Code:
On Error Resume Next
	
		Const ForWriting = 2		'// this is a constant that tells the script writer how to open then file
		Const ForAppending = 8		'// this is a constant that tells the script writer how to open then file

				
		Dim objFSO		'// this will be used to create the file system object
		Dim objFileCopy
		Dim FileWriter      		'// this is an object for writing text files
		
		
		'// ADD YOUR VARIABLES/FIELDS HERE
		Dim Fax
		Dim Email
		Dim Print
		Dim StrFilePath 
        Dim StrFolderPath
        Dim StrValue
        Dim validEmailTrigger
        Dim validFaxTrigger

        StrFilePath = "C:\AC\Work\*.pdf"
        StrFolderPath = "C:\AC\Work\"    
        StrEmailValue = "~FRO::%Email1%~"
        StrFaxValue = "~FRO::%Fax%~"
		
		
		Fax = TheFaxNumber '//Will come from RRT  ~FRO::%Fax%~
		Email = TheEmailAddress '//Will come from RRT  ~FRO::%Email%~
		Print = ThePrinter '//Will be if both RRT's are false{blank}
		
		EKOManager.StatusMessage "Fax" & TheFaxNumber
		EKOManager.StatusMessage "Email" & TheEmailAddress
		EKOManager.StatusMessage "Print" & ThePrinter
		
			
					
		strStoragePath1 = "C:\Reike\Fax\" '// Jobs to be Faxed here
		EKOManager.StatusMessage "Image Path: " & strStoragePath1
		
		strStoragePath2 = "C:\Reike\Email\" '// Jobs to be emailed here
		EKOManager.StatusMessage "Image Path: " & strStoragePath2
		
		strStoragePath3 = "C:\Reike\Print\" '// Jobs to be printed here
		EKOManager.StatusMessage "Image Path: " & strStoragePath3
		
		Set objFSO = CreateObject("Scripting.FileSystemObject")' this is where you would use the customer's special COM object instead

		Set Folder = objFSO.CreateFolder(strStoragePath1)
		
		Set Folder = objFSO.CreateFolder(strStoragePath2)
		
		Set Folder = objFSO.CreateFolder(strStoragePath3)
		


        If Email = StrEmailValue Then
           validEmailTrigger = "True"
        Else   
           validEmailTrigger = "False"
        End If
        
        If Email = StrFaxValue Then
           validFaxTrigger = "True"
        Else
           validFaxTrigger = "False"
        End If


        'Print'
        If(validEmailTrigger = "True" ) AND (validFaxTrigger = "True" )Then
           If objFSO.FolderExists (StrFolderPath )Then
    	        objFSO.MoveFile StrFilePath, strStoragePath3 
           End If
        Else
           'Fax'
            If validEmailTrigger = "False" Then
	             If Email = TheEmailAddress Then
		            If objFSO.FolderExists (StrFolderPath )Then
		    	        objFSO.MoveFile StrFilePath, strStoragePath2 
		            End If
	             End If
            Else
	            'Email'
                If validFaxTrigger = "False" Then
		           If Fax = TheFaxAddress Then
		    	        If objFSO.FolderExists (StrFolderPath )Then
			    	        objFSO.MoveFile StrFilePath, strStoragePath1
				        End If
			        End If
		        End If
            End If
        End If
 
[0] Take out the "on error resume next" at the top. It works against you.

[1] There are two sources of error in your configuration of having wildcard in the source file spec and having a directory as the destinationl. And you've verified the existence of the destination directories.
[1.1] There isn't any file of pdf extension in the source directory, or
[1.2] There is some file, say a.pdf, in the source directory and there exists a file of the same name, a.pdf, in the destination directory.
 
I have verified that the pdf files are in existence and they actually move via visual studio but not when the script is executed via CScript. Is there a way to walk through CScript.exe line by line to determine the problem?
 
determine the problem
comment out the On Error Resume Next instruction.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The script written as such will error out executing more than one time successively, as the desired files have all moved. Is that what is happening?

There may be debugger to walk through cscript, even provisioned by ms itself. I don't use any. Insert here and there of critical importance, your judgment and common sense, error checking and/or echo some message are usually sufficient. But if one is very inexperienced yet, it may be taxing on pertinent judgement and that's how progress is made.
 
No - The files are not moving at all when the script is executed. but walking through with Visual Studio they will move. So I'm not sure of the differences and/or what the problem is.

Why would the code execute successfully in Visual Studio and not in CScript.exe?
 
Make sure your value templates of some kind be substituted with intended data ("~FRO::%Email1%~", etc...) when you execute the script outside of any application. Literally, those template cannot be the name of any directory given it contains forbidden characters.
 
I had a similar issue some years back where I had to use copyfile and deletefile instead of movefile. I can't recall what the issue with movefile was, but here's a snippet of what I did to get around it:
Code:
fso.CopyFile "\\server3\common\D241BNQ*.pdf", "\\server04\shares\common\D241BNQ\", True
fso.CopyFile "\\server3\common\Index_D241BNQ*.pdf", "\\server04\shares\common\index\D241BNQ\", True
fso.DeleteFile "\\server3\common\D241BNQ*.pdf", True
fso.DeleteFile "\\server3\common\Index_D241BNQ*.pdf", True
 
Thank you everyone. removing the on error command allowed me to solve the problem. I appreciate everyone's help! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top