Page 1 of 1

Read and create files with . bat

Posted: 29 Oct 2013 18:39
by miriam.molt86
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:

Re: Read and create files with . bat

Posted: 29 Oct 2013 19:46
by foxidrive
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.

Re: Read and create files with . bat

Posted: 30 Oct 2013 02:53
by miriam.molt86
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

Re: Read and create files with . bat

Posted: 30 Oct 2013 06:16
by ShadowThief

Re: Read and create files with . bat

Posted: 30 Oct 2013 06:16
by ShadowThief
And also http://ss64.com/nt/for_f.html because I'm apparently only allowed to post two URLs at once.

Re: Read and create files with . bat

Posted: 02 Nov 2013 03:17
by trebor68
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.

Re: Read and create files with . bat

Posted: 02 Nov 2013 07:15
by penpen
To create an empty file, just use:

Code: Select all

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

penpen

Re: Read and create files with . bat

Posted: 27 Nov 2013 23:52
by shayanjameel08
Type "help for" on the command prompt for more information. (don't know if that works in whatever "DOS" you are telling)