Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

batch file to copy numbered files from one dir to another

Posted on 2014-04-21
16
Medium Priority
?
529 Views
Last Modified: 2014-04-22
I have a site that has a file folder that I need to create new files for an older program to work.
I have this a VB program that collects the necessary file numbers and will call the batch file.

The client has requested the batch file as they can change as needed on the fly

It should run the following code at a command line; ADD1 3681 1 100

THIS SHOULD ADD A 100 COPIES OF THE FILES BASED ON A FILE NAMED 3681 IN THE FOLDER THIS FILE EXIST IN, BUT IT DOES  NOT INCREMENT  result1

Tahnk you Experts...Help!!
rem Add1.bAT File for file creation
rem repeating loop to create files for future work 
rem 1st var Starting file number
rem  2nd var is the # of time to run the sequence
Rem 3rd var is the number to add to the starting number
rem ---------------- For loop
rem 1,1,200 Means:
rem	start = 1
rem	increment per step = 1
rem	end = 200
rem *************************************
rem start of code

setlocal EnableDelayedExpansion
@echo off 

set IntCopy=%1.*
set /a result=%1+%3


FOR /L %%A IN (1,1,%2) DO (

Rem **** none of the below  work
Rem **** they return "result.*
Rem **** I need result1 = result +1 & ".*"
rem set result1=!result!.*
rem set result1=!result.*
set result1=%result.*
rem set result1=%result%.*

echo These are the calcs
echo result is; %result% 
echo  3 result1 is; %result1% 
echo  IntCopy is; %IntCopy%
pause

copy %IntCopy% %Result1%

Rem **** Then I need to increment by 1
set result=!result+%3
echo result B4 Loop is %result% 
pause  
ECHO %%A
 )
pause

Open in new window

0
Comment
Question by:mdlp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
16 Comments
 
LVL 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 400 total points
ID: 40013254
the 'set' below ... increment by 1 is adding to 'result' instead of 'result1', it should be:

set /a result1=!result1+%3

(and the echo command is echoing result instead of result1 as well)
0
 

Author Comment

by:mdlp
ID: 40013313
Gerwin, thank you , but I also need set result1=%result.* to be 3681.*, could you help me here also?
0
 

Author Comment

by:mdlp
ID: 40013326
I am sorry for the name being wrong, I started in one direction and then changed, without changing the name of the question.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40013394
No problem, did you see I've added the /a - that's probably why it isn't adding.
0
 

Author Comment

by:mdlp
ID: 40013447
Yes, I actually deleted the /a I had it in an earlier version, but changed it during one of my attempts to fix it.

But the line I need help on also is the first line after the FOR command:
I tried it with both % and !, I left all my attempts in the code I posted.

set result1=%result.*

Should take the value of the incremented number that your orig post fixed and then append ".*" to the end

I have attached the screen shot of what my problem is, instead of this returning: the incremented number of result with .* appended to it. It returns  "result.*" in alpha not the numeric form. Please see the 3rd from the bottom line of the screen print

Thank you again
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40013516
You forgot to post a screenshot?

But about your goal: you want 100 copies of a file named 3681 like this:

3681.1
3681.2
...
3681.100
0
 

Author Comment

by:mdlp
ID: 40013560
ADD1 3681 1 100

3681 in this example is the master file number

I have 3681.100 -3681.150
I need a 100 of what ever the count is of the selected file.

I would then have 3682 to 3782.100 - 150

(100 * the file count of 3681) for each 3682 - 3782

I know it seems way off, but that is what I need.

It is an old Photo archive program that a client uses.

Thank you again, I am sorry, I was not very clear.
0
 

Author Comment

by:mdlp
ID: 40013564
0
 

Author Comment

by:mdlp
ID: 40013947
I do not understand, did I do something wrong?
did I place this in the wrong place?
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40014470
I'm still having trouble understanding what you require.

When you say Master File Number 3681, you mean the file name is 3681 and when you say 3681.100 -3681.150 you mean that you already have 51 files named: 3681.100, 3681.101, 3681.102 ... 3681.149 and 3681.150

Then if you do: ADD1 3681 1 100 - you expect to get another 100 files that are copies of the existing 3681.100-150 series to a new series starting with 3682, like this:

3681.100 copy ->  3682.100
3681.101 copy ->  3682.101
...
3681.150 copy ->  3682.150

I don't get where  you've got the 3782 from.

Maybe you can post an simple list (Excel) that has your requirements with the existing file names and the new series, with for example 10 new files (so: ADD1 3681 1 10).

Thanks
0
 
LVL 85

Accepted Solution

by:
oBdA earned 1600 total points
ID: 40014542
Try if this script does what you want. It's currently in test mode and will only display the "copy" commands it would normally run. Remove the uppercase ECHO in front of "copy" in line 24 to run it for real.
@echo off 
setlocal enabledelayedexpansion

if "%~3"=="" (
	echo Syntax:
	echo %~nx0 ^<Source file number^> ^<Target offset^> ^<Iterations^>
	pause&goto :eof
)
set SourceFileNumber=%~1
set TargetOffset=%~2
set Iterations=%~3
REM *** '%~dp0' expands to the script's folder, including a traling backslash
set SourceFolder=%~dp0

if not exist "%SourceFolder%%SourceFileNumber%.*" (
	echo No source file matching '%SourceFolder%%SourceFileNumber%.*' found.
	pause&exit /b 1
)
for /l %%i in (%TargetOffset%, 1, %Iterations%) do (
	set /a CurrentIndex = %%i - TargetOffset + 1
	set /a TargetFileNumber = SourceFileNumber + %%i
	for %%a in ("%SourceFolder%%SourceFileNumber%.*") do (
		echo [!CurrentIndex!/%Iterations%] Creating '!TargetFileNumber!%%~xa' ...
		ECHO copy "%%a" "%SourceFolder%!TargetFileNumber!%%~xa"
	)
)

Open in new window

And note that if you create 100 copies starting at 3682 , the last index will be 3781, not 3782.
0
 

Author Closing Comment

by:mdlp
ID: 40015173
I am sorry, this is the worst part of EE, having to split points, Gerwin, you worked so hard and did give me the initial /a that was plaguing me.  

ObDa, you hit the nail on the head, it worked perfectly!

 so if I have split incorrectly please let me know.  I wish I could give both of you 500, but EE will not let us!-(
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40015257
@mdlp - No need for apologies, you are the customer :)
0
 

Author Comment

by:mdlp
ID: 40015319
Thank you, but I am also a business man that always wants to reward hard work, thank again
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Simple Linear Regression

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question