Solved

batch file to copy numbered files from one dir to another

Posted on 2014-04-21
16
505 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
  • 8
  • 5
16 Comments
 
LVL 37

Assisted Solution

by:Gerwin Jansen
Gerwin Jansen earned 100 total points
Comment Utility
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
Comment Utility
Gerwin, thank you , but I also need set result1=%result.* to be 3681.*, could you help me here also?
0
 

Author Comment

by:mdlp
Comment Utility
I am sorry for the name being wrong, I started in one direction and then changed, without changing the name of the question.
0
 
LVL 37

Expert Comment

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

Author Comment

by:mdlp
Comment Utility
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 37

Expert Comment

by:Gerwin Jansen
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:mdlp
Comment Utility
0
 

Author Comment

by:mdlp
Comment Utility
I do not understand, did I do something wrong?
did I place this in the wrong place?
0
 
LVL 37

Expert Comment

by:Gerwin Jansen
Comment Utility
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 82

Accepted Solution

by:
oBdA earned 400 total points
Comment Utility
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
Comment Utility
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 37

Expert Comment

by:Gerwin Jansen
Comment Utility
@mdlp - No need for apologies, you are the customer :)
0
 

Author Comment

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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now