hem852 Posted May 8, 2008 Author Share Posted May 8, 2008 Jaclaz,I now have it working perfectly, just needed a little tweaking and I was able to do this with the help of thehttp://www.robvanderwoude.com/site you pointed me towards.Thank you very much.RegardsJohn Link to comment Share on other sites More sharing options...
Yzöwl Posted May 8, 2008 Share Posted May 8, 2008 Could you please post your completed script, to both help followers of the topic and to allow improvements alternetives and comments.Thank you.In the meantime I'll provide a, probably crude, vbscript which may provide an alternative:Option ExplicitDim objFSO, objFile, objDir, N, File, strFNA, strOFN, strEXT'------------------------------------------------------'Please supply your Source and Target Directories below'------------------------------------------------------Const SourceDir = "D:\Dir1\"Const TargetDir = "F:\Dir2\"Set objFSO = CreateObject("Scripting.FileSystemObject")If Not objFSO.FolderExists(SourceDir) Then MsgBox "The folder """ & SourceDir & """ does not exist", 0, _ "Missing source folder" WScript.quitEnd IfIf Not objFSO.FolderExists(TargetDir) Then On Error Resume Next objFSO.CreateFolder(TargetDir) If Err.number > 0 Then MsgBox "Cannot create the folder """ & SourceDir & """", 0, _ "Missing target folder" WScript.Quit End IfEnd IfOn Error Goto 0Set objFSO = CreateObject("Scripting.FileSystemObject")Set objDir = objFSO.GetFolder(SourceDir)For Each File In objDir.Files N=Now strFNA = "_" & Right(100+Day(N),2) & "-" & Right(100+Month(N),2) & "-" & _ Right(Year(N),2) & "_" & Right(100+Hour(N),2) & "-" & Right(100+Minute(N),2) objFSO.CopyFile File.Name, TargetDir & "\" & objFSO.GetBaseName(File.Name) & _ strFNA & "." & objFSO.GetExtensionName(File.Name)NextThis script will copy all files in the source directory to the target directory (both specified by you). The copied files should have the appended date strings you requested! Link to comment Share on other sites More sharing options...
hem852 Posted May 12, 2008 Author Share Posted May 12, 2008 The final batch file is shown below. It works like a dream in our scheduler so thanks to all for your help in getting this working. The only remaining issue I have to resolve is that this overwrites the exisiting file if run more than once per day for the same file. Ideally I need to be keeping all of the last weeks files. I tried to include the time element in the newfile variable but could not get this working because %time% contains characters that are not legal in file names. Is there a way of splitting the time elements or changing the delimiter it uses?@ECHO OFFREM #### Fetch parameters from command line ####SET DTS=%1SET file1=%2REM #### Configure UNC path ####net use \\server\d$ /user:DOMAIN\username passwordREM #### Split the cube filename into useable portions ####CALL :PARSEVAR %file1%FOR %%A IN ( file1 fullname fullpath drive filename fileext firstpart addedpart newfile) DO SET %%A:EOFREM #### Check if cube directory exists and create if it does not ####IF NOT EXIST E:\CognosData\Cubes\%filename% md E:\CognosData\Cubes\%filename%REM #### Copy cube file from build server to app server ####COPY %file1% %newfile%REM #### Now run the cubeswap code ####set JAVA_HOME=../../../bin/jre/1.4.2/set CRN_HOME=../../../set JAR_HOME=%CRN_HOME%webapps/p2pd/WEB-INF/libset CLASSPATH=.set CLASSPATH=%CLASSPATH%;%JAR_HOME%/axis.jarset CLASSPATH=%CLASSPATH%;%JAR_HOME%/axisCrnpClient.jarset CLASSPATH=%CLASSPATH%;%JAR_HOME%/commons-discovery.jarset CLASSPATH=%CLASSPATH%;%JAR_HOME%/commons-logging.jarset CLASSPATH=%CLASSPATH%;%JAR_HOME%/jaxrpc.jarset CLASSPATH=%CLASSPATH%;%JAR_HOME%/saaj.jarset CLASSPATH=%CLASSPATH%;%JAR_HOME%/xml-apis.jarset CLASSPATH=%CLASSPATH%;%JAR_HOME%/xercesImpl.jar"%JAVA_HOME%bin/java.exe" -classpath %CLASSPATH% CubeSwap -dispatchername="http://llsvr-bur-3315:9300" -datasource=%DTS% -url="http://server/p2pd/servlet/dispatch" -windowscube="%newfile%" -username="user" -password="pass" -namespaceid="0001":PARSEVARSET fullname=%~1SET fullpath=%~f1SET drive=%~d1SET filename=%~n1SET fileext=%~x1SET firstpart=%~dpn1SET addedpart=%DATE:/=-%SET newfile="E:\CognosData\Cubes\%filename%\%filename%_%addedpart%%fileext%":GOTO EOFThanks again for all your help.Very much appreciated.John Link to comment Share on other sites More sharing options...
Smiley357 Posted May 13, 2008 Share Posted May 13, 2008 If you dont want to replace a file all you have to do is check to see if the file exist. If so skip it.IF EXIST File GOTO EOF If you want to add time to the file name here is how to remove the ":" and "." Im sure someone is going to come along with a better way.. jaclaz.. but this answers your question just like my last code did. LOLSet FileTime=%Time::=% (this removes the ":" from time and saves it in FileTime)Set FileTime=%FileTime:.=% (this removes the "." from FileTime and saves it in FileTime) Link to comment Share on other sites More sharing options...
hem852 Posted May 13, 2008 Author Share Posted May 13, 2008 Thank you very much smiley.Much appreciated. Link to comment Share on other sites More sharing options...
jaclaz Posted May 13, 2008 Share Posted May 13, 2008 (edited) A couple of small things:1) the :EOF label is unneeded / wrong, :EOF is an implied label in 2K/XP that means End Of File.When you CALL a subroutine, the final GOTO :EOF is interpreted like the "RETURN" statement in most languages, i.e. the program understands that there is nothing else to do there and goes back to the first instruction after the CALL statement.2) You do not actually need the subroutine, the FOR loop and the SET commands.This should do:IF NOT EXIST "E:\CognosData\Cubes\%~n2" md "E:\CognosData\Cubes\%~n2"COPY %2 "E:\CognosData\Cubes\%~n2\%~n2_%DATE:/=-%%~x2"(a little less readable, but definitely simpler) jaclaz Edited May 13, 2008 by jaclaz Link to comment Share on other sites More sharing options...
Yzöwl Posted May 13, 2008 Share Posted May 13, 2008 Here is a quick untested file which may help you. This file is not here as learning material, but it should be useful nonetheless.Ren2FnDT.cmd@Echo off&SetlocalIf %1' Equ ' (Set/p "f_=Enter the Full Unquoted File Name to process: ") Else ( Set "f_=%~1")If Not Exist "%f_%" (Echo: File Not Found&Ping -n 6 127.0.0.1>Nul&Goto :Eof)Set "s_=E:\CognosData\Cubes":_F Dir/b/ad "%s_%">Nul 2>&1||(Echo: Destination Directory Not Found&Echo: Echo: Enter the Full Unquoted Destination Directory Path:&Echo: Echo: OR&Echo: Enter X to Exit&Set/p "s_=") If /i %s_% Equ x Goto :Eof For /f "delims=" %%# In ("%f_%") Do Set "n_=%%~n#"&Set "e_=%%~x#" Call :_B:_O If Not Exist "%s_%\%n_%" (MD "%s_%\%n_%"2>Nul||Goto :Eof) Copy "%f_%" "%s_%\%n_%\%n_%%d_t%%e_%" Goto :Eof:_B Call :_D y m d Call :_T h n Set d_t=_%d%-%m%-%y%_%h%-%n%&Goto :Eof :_D Setlocal enableextensions Set "t_=2"&If "%date%z" Lss "A" Set "t_=1" For /f "skip=1 tokens=2-4 delims=(-)" %%a In ( 'Echo:^|Date') Do ( For /f "tokens=%t_%-4 delims=.-/ " %%d In ( 'Date/t') Do ( Set "%%a=%%d"&Set "%%b=%%e" Set "%%c=%%f")) Endlocal&Set "%1=%yy%"&Set "%2=%mm%"&Set "%3=%dd%"&Goto :Eof :_T Setlocal enableextensions For /f "tokens=5-8 delims=:. " %%a In ('Echo:^|Time') Do ( Set "hh=%%a"&Set "nn=%%b") If 1%hh% Lss 20 Set "hh=0%hh%" Endlocal&Set "%1=%hh%"&Set "%2=%nn%"&Goto :EofYou can either run it as it is and answer the questions, or drag and drop the file onto it, or I suppose enter the path and file name, (quoted if contains spaces).<Note>This is untested and hasn't been written with full error trapping etc. It should work for the topic starters location and some others but not all! Link to comment Share on other sites More sharing options...
hem852 Posted June 3, 2008 Author Share Posted June 3, 2008 Hi,With a fair amount of help I have written the following batch file to move some files about, do some renaming and stuff like that. (I'm fairly new to this stuff so please forgive if this is badly written)@ECHO OFFREM ---- Fetch parameters from command line ----SET dts=%1SET file1=%2REM ---- Configure UNC path ----net use \\llsvr-bur-3334\d$ /user:LLEE\ca.autosys auto5y5REM ---- Split the cube filename into useable portions ----CALL :PARSEVAR %file1%:EOFREM ---- Create cube working directories if they do not exist ----IF NOT EXIST E:\CognosData\Cubes\%filename% md E:\CognosData\Cubes\%filename%IF NOT EXIST E:\CognosData\Cubes\%filename%\old md E:\CognosData\Cubes\%filename%\oldREM ---- Rename any existing mdc in old dir to .bak and copy exisitng mdc to old directory ----RENAME E:\CognosData\Cubes\%filename%\old\*.mdc *.bak copy E:\CognosData\Cubes\%filename%\*.mdc E:\CognosData\Cubes\%filename%\old\del E:\CognosData\Cubes\%filename%\*.mdcREM ---- Compact files in old directory to save disk space ----e:cd E:\CognosData\Cubes\%filename%\old\compact.exe /C REM ---- Copy mdc file from build server ----COPY /V %file1% %newfile%IF ERRORLEVEL 1 GOTO :ERRORdel E:\CognosData\Cubes\%filename%\old\*.bakREM ---- Navigate to Cubeswap Directory & call Cognos Java App ---d:cd\"program files"\cognos\c8\webapps\utilities\cubeSwapSET JAVA_HOME=../../../bin/jre/1.4.2/SET CRN_HOME=../../../SET JAR_HOME=%CRN_HOME%webapps/p2pd/WEB-INF/libSET CLASSPATH=.SET CLASSPATH=%CLASSPATH%;%JAR_HOME%/axis.jarSET CLASSPATH=%CLASSPATH%;%JAR_HOME%/axisCrnpClient.jarSET CLASSPATH=%CLASSPATH%;%JAR_HOME%/commons-discovery.jarSET CLASSPATH=%CLASSPATH%;%JAR_HOME%/commons-logging.jarSET CLASSPATH=%CLASSPATH%;%JAR_HOME%/jaxrpc.jarSET CLASSPATH=%CLASSPATH%;%JAR_HOME%/saaj.jarSET CLASSPATH=%CLASSPATH%;%JAR_HOME%/xml-apis.jarSET CLASSPATH=%CLASSPATH%;%JAR_HOME%/xercesImpl.jar"%JAVA_HOME%bin/java.exe" -classpath %CLASSPATH% CubeSwap -dispatchername="http://llsvr-bur-3333:9300" -datasource=%dts% -url="http://llsvr-bur-3333:9300/p2pd/servlet/dispatch" -windowscube="%newfile%" -username="user" -password="pass" -namespaceid="0001"GOTO :END:ERRORCOPY /V E:\CognosData\Cubes\%filename%\old\*.mdc E:\CognosData\Cubes\%filename%\temp.mdc d:cd\"program files"\cognos\c8\webapps\utilities\cubeSwapSET JAVA_HOME=../../../bin/jre/1.4.2/SET CRN_HOME=../../../SET JAR_HOME=%CRN_HOME%webapps/p2pd/WEB-INF/libSET CLASSPATH=.SET CLASSPATH=%CLASSPATH%;%JAR_HOME%/axis.jarSET CLASSPATH=%CLASSPATH%;%JAR_HOME%/axisCrnpClient.jarSET CLASSPATH=%CLASSPATH%;%JAR_HOME%/commons-discovery.jarSET CLASSPATH=%CLASSPATH%;%JAR_HOME%/commons-logging.jarSET CLASSPATH=%CLASSPATH%;%JAR_HOME%/jaxrpc.jarSET CLASSPATH=%CLASSPATH%;%JAR_HOME%/saaj.jarSET CLASSPATH=%CLASSPATH%;%JAR_HOME%/xml-apis.jarSET CLASSPATH=%CLASSPATH%;%JAR_HOME%/xercesImpl.jar"%JAVA_HOME%bin/java.exe" -classpath %CLASSPATH% CubeSwap -dispatchername="http://llsvr-bur-3333:9300" -datasource=%dts% -url="http://llsvr-bur-3333:9300/p2pd/servlet/dispatch" -windowscube="E:\CognosData\Cubes\%filename%\temp.mdc" -username="user" -password="pass" -namespaceid="0001"ECHO.ECHO Cubeswap FailedECHO.GOTO :END:PARSEVARSET fullname=%~1SET fullpath=%~f1SET drive=%~d1SET filename=%~n1SET fileext=%~x1SET firstpart=%~dpn1SET FileTime=%Time::=-% SET FileTime=%FileTime:.=-%SET addedpart=%DATE:/=-%_%FileTime%SET addedpart=%addedpart: =%SET newfile="E:\CognosData\Cubes\%filename%\%filename%_%addedpart%%fileext%":GOTO EOF:ENDThe batch file seems to work perfectly until the :ERROR part of the script is needed. For some reason that I cannot quite work out, the copy command only copies about 21k of the file. Does anyone have any idea what might be causing this? Everything else is working fine, even the rest of the :ERROR section.Thanks in advance for any help.RegardsJohnFYI : This is being run on Windows 2003 Server standard edition. Link to comment Share on other sites More sharing options...
jaclaz Posted June 3, 2008 Share Posted June 3, 2008 Change this:REM ---- Copy mdc file from build server ----COPY /V %file1% %newfile%IF ERRORLEVEL 1 GOTO :ERRORto this:REM ---- Copy mdc file from build server ----ECHO ONCOPY /V %file1% %newfile%IF ERRORLEVEL 1 GOTO :ERRORand this::ERRORCOPY /V E:\CognosData\Cubes\%filename%\old\*.mdc E:\CognosData\Cubes\%filename%\temp.mdc d:cd\"program files"\cognos\c8\webapps\utilities\cubeSwapto this::ERRORCOPY /V E:\CognosData\Cubes\%filename%\old\*.mdc E:\CognosData\Cubes\%filename%\temp.mdc d:cd\"program files"\cognos\c8\webapps\utilities\cubeSwapECHO OFFand post output when run.once again you can remove the set statements that are not used:SET fullname=%~1SET fullpath=%~f1SET drive=%~d1SET filename=%~n1SET fileext=%~x1SET firstpart=%~dpn1Can you also post the actual value of the %CLASSPATH% variable at the end of all the SET statements, the command line must become ENORMOUSLY long, and that may be a cause of problems. jaclaz Link to comment Share on other sites More sharing options...
Yzöwl Posted June 3, 2008 Share Posted June 3, 2008 Can you also post the actual value of the %CLASSPATH% variable at the end of all the SET statements, the command line must become ENORMOUSLY long, and that may be a cause of problems. jaclazThat line is over 1500 characters long before the first variable of unknown character length, (%dts%), alone. There is a limit of 1024 characters hence one of the problems! Link to comment Share on other sites More sharing options...
hem852 Posted June 5, 2008 Author Share Posted June 5, 2008 Hi I found that if instead of doing thisCOPY /V E:\CognosData\Cubes\%filename%\old\*.mdc E:\CognosData\Cubes\%filename%\temp.mdcI do thisRENAME E:\CognosData\Cubes\%filename%\old\*.mdc temp.mdccopy /V E:\CognosData\Cubes\%filename%\old\temp.mdc E:\CognosData\Cubes\%filename%\temp.mdcThen everything works fine.In the script everything from SET JAVA_HOMEto-namespaceid="0001"including the %CLASSPATH% stuff is code provided by IBM Cognos and is used heavily by most Cognos 8 server implementations so I am assuming it would not be a problem. Thanks for all your help.RegardsJohn Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now