Read and create files with . bat

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
miriam.molt86
Posts: 2
Joined: 29 Oct 2013 18:25

Read and create files with . bat

#1 Post by miriam.molt86 » 29 Oct 2013 18:39

Hello everyone!
I'm new to this forum but I thank in advance anyone help me!

I am writing to ask for help, I need to create a .Bat file that performs the following tasks:

Given a specific path ( eg c:\source ) in which there is a single file A_stringSource.Txt (Example A_123456789.txt )
write in another folder ( eg c:\destination) 5 empty files .dat format name with a string that I decide + the string of the name of the source file. So in the destination folder there should be 5 empty files with name:
StringDestination1+StringOrigin.Dat
StringDestination2+StringOrigin.Dat
StringDestination3+StringOrigin.Dat
StringDestination4+StringOrigin.Dat
StringDestination5+StringOrigin.Dat

The destination string is fixed and I'll decide within the batch file. The user does not insert any data.

For example, in our case:
string1123456789.dat
string2123456789.dat
string3123456789.dat
string4123456789.dat
string5123456789.dat

I hope I have explained well my problem.
I will be very much grateful to anyone who can solve this problem! :D
One smack for all! :roll:

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Read and create files with . bat

#2 Post by foxidrive » 29 Oct 2013 19:46

Are you doing some scripting for a school course?

Have a go and see what you can come up with, and then ask some specific questions about the problems you find.

miriam.molt86
Posts: 2
Joined: 29 Oct 2013 18:25

Re: Read and create files with . bat

#3 Post by miriam.molt86 » 30 Oct 2013 02:53

Good morning,
  I'm not a student.
I'm trying to make this script for the integration of data between two programs for my small company family.
I hope someone help me to solve the problem.
If you have additional questions or requests do not hesitate to contact me.
Have a nice day,
Miriam

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Read and create files with . bat

#4 Post by ShadowThief » 30 Oct 2013 06:16


ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Read and create files with . bat

#5 Post by ShadowThief » 30 Oct 2013 06:16

And also http://ss64.com/nt/for_f.html because I'm apparently only allowed to post two URLs at once.

trebor68
Posts: 146
Joined: 01 Jul 2011 08:47

Re: Read and create files with . bat

#6 Post by trebor68 » 02 Nov 2013 03:17

Here a example code:

Code: Select all

@echo off
set StringDestination=###
for %%a in ("C:\source\*.txt") do set StringOrigin=%%~na
for /l %%d in (1, 1, 5) do echo File: "C:\OutputFolder\%StringDestination%%%d%StringOrigin%.dat"

The batch find one txt-file in the folder "C:\source\". If you have more files the batch is only used one file.
The last row will display the possible file name.

It is possible to make empty files. But if you use a file that is exist then you overwrite this file.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Read and create files with . bat

#7 Post by penpen » 02 Nov 2013 07:15

To create an empty file, just use:

Code: Select all

copy nul "C:\path\a file.ext"

penpen

shayanjameel08
Posts: 10
Joined: 21 Nov 2013 01:07

Re: Read and create files with . bat

#8 Post by shayanjameel08 » 27 Nov 2013 23:52

Type "help for" on the command prompt for more information. (don't know if that works in whatever "DOS" you are telling)

Post Reply