• Announcements

    • xper

      MSFN Sponsorship and AdBlockers!   07/10/2016

      Dear members, MSFN is made available via subscriptions, donations and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, become a site sponsor and ads will be disabled automatically and by subscribing you get other sponsor benefits.
Sign in to follow this  
Followers 0
hem852

Batch File copy and rename with date

26 posts in this topic

Hi

I am trying to write a batch file that will copy a file from one network drive to another and rename it on the new location so the filename has the date at the end.

Below is what I have so far but this is not working. It hits problems with files that have spaces in them, sometimes returns the error 'NET is not a valid command' and does not wait until the file is finished copying before moving on to the next command.

I can also only get the date added to the begining of the file when ideally I need it at the end.


@@echo off
REM Fetch the file name from the command line
SET FILENAME=%2
SET DTS=%1
net use \\llsvr-bur-3330\d$ /USER:DOMAIN\username password
net use \\llsvr-bur-3333\e$ /USER:DOMAIN\username password

REM Create the date and time elements.
For /f "tokens=1-7 delims=:/-, " %%i in ('echo exit^|cmd /q /k"prompt $D $T"') do (
For /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do (
set dd=%%i
set mm=%%j
set yy=%%k
set hh=%%l
set min=%%m
set ss=%%n
)
)


REM COPY FILE AND RENAME WITH DATE AND TIME APPENDED

SET NEW_FILE=%dd%-%mm%-%yy%_%hh%%min%_%NAME%
START /WAIT /B COPY /V %NAME% %NEW_FILE%

CALL CUBESWAP.bat

Could someone possibly give me some help sorting this out please? Sorry if this seems like a bit of a hopeless attempt, its my first attempt at windows batch files! Thanks in advance for any help.

John

0

Share this post


Link to post
Share on other sites

From the fact that you are using the For /F syntax, I get that you are going to run this in 2K/XP or later OS.

In such cases, it is advised NOT to use the .bat extension but rather the .cmd one, but it is not needed, it's just a way to make sure you won't run it in DOS/9x/Me.

The problem should be only where you "expand" the variables and "pass" them to a command.

The default separator is the space, thus a name that includes a space is seen by the command processor as TWO parameters.

Simply enclose the variables with quotes.

START /WAIT /B COPY /V "%NAME%" "%NEW_FILE%"

This should apply also to "FILENAME" which is given as second parameter when calling the batch.

But I seem to fail seeing the variable "NAME" defined anywhere in the batch, I guess it should be everywhere either "FILENAME" or "NAME". :unsure:

You need to strip the quotes in order to add the date in front of the name, and enclose the date+name in "new" quotes.

SET NEW_FILE="%dd%-%mm%-%yy%_%hh%%min%_%NAME%"

There are several ways to do so, most notably using a CALL with parameter and expanding %~1, or something like SET NAME=%NAME:"=%.

But the line:

START /WAIT /B COPY /V "%NAME%" "%NEW_FILE%"

Won't work correctly as it misses the PATH to both the source and destination files.

Check this site:

http://www.robvanderwoude.com

And these threads:

http://www.msfn.org/board/Rename-File-With...-Fi-t47812.html

http://www.msfn.org/board/index.php?act=idx/showtopic=37572

To see some examples, post again if you need more help.

jaclaz

0

Share this post


Link to post
Share on other sites

From your coded section, I honestly have no idea of your intentions. You're setting two variables using parameters given at script invokation; these are being set to names which aren't used. You have two variables in your script which aren't defined and a nested for loop which isn't used at all.

Apart from that the idea is not very good. If you want to rename using dates etc. the only useful format would be YYYY-MM-DD_hh-mm_filename. The reason for this is that you can sort your files appropriately. Using your current attempted system you could have files ordered thus:

02-05-07_23-14_FileName.ext

06-01-04_09-13_FileName.ext

06-05-08_16-25_FileName.ext

21-07-05_11-06_FileName.ext

27-03-98_03-34_FileName.ext

Instead of
1998-03-27_03-34_FileName.ext

2004-01-06_09-13_FileName.ext

2005-07-21_11-06_FileName.ext

2007-05-02_23-14_FileName.ext

2008-05-06_16-25_FileName.ext

Try looking at what you want again then give us a little bit more pertinent information.

0

Share this post


Link to post
Share on other sites

I think this is what you are looking for. Save this as a bat or cmd file.

@echo off

xcopy /I /E /H d:\ e:\
cd "e:dir of files to be renamed"
for %%i in (*.*) do Call :rename "%%i"


:rename
set oldname=%~1
Set FileDate=%date:/=%
set newname=%FileDate%-%oldname%
ren "%oldname%" "%newname%"

If you dont want the day of the week in your file name change the set newname to this:

set newname=%FileDate:~4%-%oldname%

Edited by Smiley357
0

Share this post


Link to post
Share on other sites

BTW Smiley357, the output of %DATE% is different depending upon locale etc.

For hem352, I'd suggest that %DATE:~4% resolves to 2008 which isn't what I expect you wanted!

0

Share this post


Link to post
Share on other sites

That’s true, I forget about the euro date difference. But hopefully he gets the idea and can modify the string however needed.

0

Share this post


Link to post
Share on other sites
You're setting two variables using parameters given at script invokation; these are being set to names which aren't used.

To clarify, they are used by the cubeswap.bat script called at the end of the script.

You have two variables in your script which aren't defined.

I think there is only one not defined and that was a simple typo where I am having to copy from one screen to another because the machine we are trying to do this on has no access to the web. The variables NAME and FILENAME should be the same thing. Sorry about that.

Apart from that the idea is not very good. If you want to rename using dates etc. the only useful format would be YYYY-MM-DD_hh-mm_filename. The reason for this is that you can sort your files appropriately. Using your current attempted system you could have files ordered thus:

02-05-07_23-14_FileName.ext

06-01-04_09-13_FileName.ext

06-05-08_16-25_FileName.ext

21-07-05_11-06_FileName.ext

27-03-98_03-34_FileName.ext

Instead of

1998-03-27_03-34_FileName.ext

2004-01-06_09-13_FileName.ext

2005-07-21_11-06_FileName.ext

2007-05-02_23-14_FileName.ext

2008-05-06_16-25_FileName.ext

What I want ideally is the date after the filename but before is the only way I could get this to work. I was hoping someone could explain how I swap these around without messing up the file extension. If the date has to go before then putting year first would make finding a file difficult as over the course of a month we are going to end up with 2400+ files in this directory at any one time. I figured it is easier to find a file amongst 80 with the same day number at the beginning than to try and attempt to find a file amongst 2400+ files all starting with the same year.

Put simply what I want to do is take file A from server A and copy it to server B renaming the copy on server B to be the original filename plus the date of copy. So a file named 'file.txt' on sever A would become 'file_dd-mm-yyyy_hh-mm.txt' on server B.

I then need to pass the fully qualified filename on server B to another script called Cubeswap.bat

I appreciate I have probably made a bit of a mess of this in the first place but as I mentioned its the first time I have ever tried to write a windows batch file and I'd rather 'have a go' before I asked for help.

The idea being, when we get this working is we can use the batch file in a scheduler to automate these copies each night.

Thanks for all the help so far, I'm still working on this so would still welcome more suggestions.

Regards

John

0

Share this post


Link to post
Share on other sites
What I want ideally is the date after the filename but before is the only way I could get this to work. I was hoping someone could explain how I swap these around without messing up the file extension. If the date has to go before then putting year first would make finding a file difficult as over the course of a month we are going to end up with 2400+ files in this directory at any one time. I figured it is easier to find a file amongst 80 with the same day number at the beginning than to try and attempt to find a file amongst 2400+ files all starting with the same year.

You can easily "parse" separately filename and extension, by using the tilde parameters substitution, see this:

http://www.robvanderwoude.com/ntfor.html

In addition, substitution of FOR variable references has been enhanced.

You can now use the following optional syntax:

%~i - expands %i removing any surrounding quotes (")

%~fi - expands %i to a fully qualified path name

%~di - expands %i to a drive letter only

%~pi - expands %i to a path only

%~ni - expands %i to a file name only

%~xi - expands %i to a file extension only

%~si - expanded path contains short names only

%~ai - expands %i to file attributes of file

%~ti - expands %i to date/time of file

%~zi - expands %i to size of file

The above works also for variables passed by CALL functions.

Something like this:

@ECHO OFF
SET file1="C:\foo withspace\foo.txt"
CALL :PARSEVAR %file%

FOR %%A IN ( file1 fullname fullpath drive filename fileext firstpart addedpart newfile) DO SET %%A

GOTO :EOF

:PARSEVAR
SET fullname=%~1
SET fullpath=%~f1
SET drive=%~d1
SET filename=%~n1
SET fileext=%~x1
SET firstpart=%~dpn1
SET addedpart=test
SET newfile="%firstpart%%addedpart%%fileext%"
GOTO :EOF

Should give you the idea.

jaclaz

0

Share this post


Link to post
Share on other sites

can you just make folders with the date in instead?

this is what i'd do..

for this example "D:\files" is the source folder and "E:\files" is desination

set CURRDATE=%DATE:/=-%

md "E:\files\%currdate%"

xcopy /e /h /y D:\files\*.* "E:\files\%currdate%\"

that would create e:\Files\07-05-2008\

or similar..

0

Share this post


Link to post
Share on other sites
can you just make folders with the date in instead?

No unfortuantely not, the application that uses the created files insists that they appear in one location only, it can only point to one directory.

John

0

Share this post


Link to post
Share on other sites
%~i - expands %i removing any surrounding quotes (")

%~fi - expands %i to a fully qualified path name

%~di - expands %i to a drive letter only

%~pi - expands %i to a path only

%~ni - expands %i to a file name only

%~xi - expands %i to a file extension only

%~si - expanded path contains short names only

%~ai - expands %i to file attributes of file

%~ti - expands %i to date/time of file

%~zi - expands %i to size of file

Thank you for this very valuable info Jaclaz, very much appreciated, I'm sure I can work with this.

John

0

Share this post


Link to post
Share on other sites

It’s all about string manipulation. Just change this line. I know this batch file changes every file in a directory but you have the function that does all the work. Just pass the file name to the function and you are good to go.

set newname=%oldname:~0,-4%-%FileDate%%oldname:~-4%

Edited by Yzöwl
fixed codebox size!
0

Share this post


Link to post
Share on other sites
It’s all about string manipulation. Just change this line. I know this batch file changes every file in a directory but you have the function that does all the work. Just pass the file name to the function and you are good to go.

set newname=%oldname:~0,-4%-%FileDate%%oldname:~-4%

If I may, NO.

The "4" parameter implies that every file has been named conforming to a (non existing) N+3 convention, i.e. ALL files need to have an extension and the extension MUST be exactly three characters long.

This is not the case always, and expecially nowadays, with the new extensions the good guys at MS invented for Office files:

http://en.wikipedia.org/wiki/Microsoft_Off...file_extensions

it is (or will be VERY common to have files with four or five characters extensions)

The internal filenames parsing of the tilde expansion uses the dot as separator between filename and its extension and it works with any length of the extension.

This can be replicated by parsing the variables and finding the position of the dot, but it is unneeded, as the above method works perfectly.

jaclaz

0

Share this post


Link to post
Share on other sites

Thanks to everyone for their help, especially Jaclaz, I now have a working script but.....

Is there a way to make the script wait for a file copy to complete before continuing? Some of the files I am using this to copy are rather big and cant take 10 minutes or so to copy.

Is there a way to get just the just the files parent directory into a variable? For example if a file is in directory c:\dir1\dir2\dir3\file is it possible to set a variable to just contain whatever dir3 may be?

Thanks again to everyone for your help. It really is greatly appreciated.

Regards

John

0

Share this post


Link to post
Share on other sites

I am not sure I understand what you are asking for.

Waiting for the completion of a filecopy process should be default.

Why don't you post your batch at the point it is now, so that we can have a look at it and maybe show you what needs to be added?

A check for ERRORLEVEL:

http://www.robvanderwoude.com/errorlevel.html

may be used, starting a second batch and checking for it's termination, or using directly something like:

start /wait cmd.exe /c call anotherbatch.cmd param1 param2

Getting just the name of last-in-tree "parent" directory should be possible parsing the %~p1 variable, using a FOR loop using the backslash as delimiter, but what is it needed for? :unsure:

jaclaz

0

Share this post


Link to post
Share on other sites

Jaclaz,

I now have it working perfectly, just needed a little tweaking and I was able to do this with the help of the

http://www.robvanderwoude.com/

site you pointed me towards.

Thank you very much.

Regards

John

0

Share this post


Link to post
Share on other sites

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 Explicit
Dim 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.quit
End If

If 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 If
End If
On Error Goto 0

Set 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)
Next

This 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!

0

Share this post


Link to post
Share on other sites

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 OFF

REM #### Fetch parameters from command line ####

SET DTS=%1
SET file1=%2

REM #### Configure UNC path ####

net use \\server\d$ /user:DOMAIN\username password

REM #### 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

:EOF

REM #### 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/lib

set CLASSPATH=.
set CLASSPATH=%CLASSPATH%;%JAR_HOME%/axis.jar
set CLASSPATH=%CLASSPATH%;%JAR_HOME%/axisCrnpClient.jar
set CLASSPATH=%CLASSPATH%;%JAR_HOME%/commons-discovery.jar
set CLASSPATH=%CLASSPATH%;%JAR_HOME%/commons-logging.jar
set CLASSPATH=%CLASSPATH%;%JAR_HOME%/jaxrpc.jar
set CLASSPATH=%CLASSPATH%;%JAR_HOME%/saaj.jar
set CLASSPATH=%CLASSPATH%;%JAR_HOME%/xml-apis.jar
set 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"



:PARSEVAR
SET fullname=%~1
SET fullpath=%~f1
SET drive=%~d1
SET filename=%~n1
SET fileext=%~x1
SET firstpart=%~dpn1
SET addedpart=%DATE:/=-%
SET newfile="E:\CognosData\Cubes\%filename%\%filename%_%addedpart%%fileext%"

:GOTO EOF

Thanks again for all your help.

Very much appreciated.

John

0

Share this post


Link to post
Share on other sites

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. :P LOL

Set 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)

0

Share this post


Link to post
Share on other sites

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 by jaclaz
0

Share this post


Link to post
Share on other sites

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&Setlocal
If %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 :Eof

You 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!

0

Share this post


Link to post
Share on other sites

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 OFF

REM ---- Fetch parameters from command line ----
SET dts=%1
SET file1=%2

REM ---- Configure UNC path ----
net use \\llsvr-bur-3334\d$ /user:LLEE\ca.autosys auto5y5

REM ---- Split the cube filename into useable portions ----
CALL :PARSEVAR %file1%
:EOF

REM ---- 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%\old

REM ---- 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%\*.mdc

REM ---- 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 :ERROR
del E:\CognosData\Cubes\%filename%\old\*.bak

REM ---- Navigate to Cubeswap Directory & call Cognos Java App ---
d:
cd\"program files"\cognos\c8\webapps\utilities\cubeSwap
SET JAVA_HOME=../../../bin/jre/1.4.2/
SET CRN_HOME=../../../
SET JAR_HOME=%CRN_HOME%webapps/p2pd/WEB-INF/lib
SET CLASSPATH=.
SET CLASSPATH=%CLASSPATH%;%JAR_HOME%/axis.jar
SET CLASSPATH=%CLASSPATH%;%JAR_HOME%/axisCrnpClient.jar
SET CLASSPATH=%CLASSPATH%;%JAR_HOME%/commons-discovery.jar
SET CLASSPATH=%CLASSPATH%;%JAR_HOME%/commons-logging.jar
SET CLASSPATH=%CLASSPATH%;%JAR_HOME%/jaxrpc.jar
SET CLASSPATH=%CLASSPATH%;%JAR_HOME%/saaj.jar
SET CLASSPATH=%CLASSPATH%;%JAR_HOME%/xml-apis.jar
SET 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

:ERROR
COPY /V E:\CognosData\Cubes\%filename%\old\*.mdc E:\CognosData\Cubes\%filename%\temp.mdc
d:
cd\"program files"\cognos\c8\webapps\utilities\cubeSwap
SET JAVA_HOME=../../../bin/jre/1.4.2/
SET CRN_HOME=../../../
SET JAR_HOME=%CRN_HOME%webapps/p2pd/WEB-INF/lib
SET CLASSPATH=.
SET CLASSPATH=%CLASSPATH%;%JAR_HOME%/axis.jar
SET CLASSPATH=%CLASSPATH%;%JAR_HOME%/axisCrnpClient.jar
SET CLASSPATH=%CLASSPATH%;%JAR_HOME%/commons-discovery.jar
SET CLASSPATH=%CLASSPATH%;%JAR_HOME%/commons-logging.jar
SET CLASSPATH=%CLASSPATH%;%JAR_HOME%/jaxrpc.jar
SET CLASSPATH=%CLASSPATH%;%JAR_HOME%/saaj.jar
SET CLASSPATH=%CLASSPATH%;%JAR_HOME%/xml-apis.jar
SET 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 Failed
ECHO.
GOTO :END

:PARSEVAR
SET fullname=%~1
SET fullpath=%~f1
SET drive=%~d1
SET filename=%~n1
SET fileext=%~x1
SET firstpart=%~dpn1
SET FileTime=%Time::=-%
SET FileTime=%FileTime:.=-%
SET addedpart=%DATE:/=-%_%FileTime%
SET addedpart=%addedpart: =%
SET newfile="E:\CognosData\Cubes\%filename%\%filename%_%addedpart%%fileext%"
:GOTO EOF

:END

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

Regards

John

FYI : This is being run on Windows 2003 Server standard edition.

0

Share this post


Link to post
Share on other sites

Change this:

REM ---- Copy mdc file from build server ----
COPY /V %file1% %newfile%
IF ERRORLEVEL 1 GOTO :ERROR

to this:

REM ---- Copy mdc file from build server ----
ECHO ON
COPY /V %file1% %newfile%
IF ERRORLEVEL 1 GOTO :ERROR

and this:

:ERROR
COPY /V E:\CognosData\Cubes\%filename%\old\*.mdc E:\CognosData\Cubes\%filename%\temp.mdc
d:
cd\"program files"\cognos\c8\webapps\utilities\cubeSwap

to this:

:ERROR
COPY /V E:\CognosData\Cubes\%filename%\old\*.mdc E:\CognosData\Cubes\%filename%\temp.mdc
d:
cd\"program files"\cognos\c8\webapps\utilities\cubeSwap
ECHO OFF

and post output when run.

once again you can remove the set statements that are not used:

SET fullname=%~1

SET fullpath=%~f1

SET drive=%~d1

SET filename=%~n1

SET fileext=%~x1

SET firstpart=%~dpn1

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

jaclaz

0

Share this post


Link to post
Share on other sites
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. :unsure:

jaclaz

That 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!
0

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.