Windows batch file issue

Discussion and support for the Windows family of operating systems.
Post Reply
DarkRanger
Registered User
Posts: 8346
Joined: 10 May 2006, 02:00
Processor: Intel i5-3750
Motherboard: Gigabyte
Graphics card: nVidia GTX 550Ti
Memory: 8GB Jetram
Contact:

Windows batch file issue

Post by DarkRanger »

I need a batch file to check if a file exists, if it does, it asks the user for a new file name, if it doesn't it creates the file and writes to it. This is the code:

Code: Select all

@echo off
set /p Filen = Please type a file name: 
echo filename is %Filen%
:existing
if exist %Filen% goto newfile
if not exist %Filen% goto newfile

:makeline
set /p linetext = Please enter a line of text: 
echo %linetext% >> %Filen%
echo File has been created!

:newfile
set /p filen = File exists. Please type a new file name: 
goto existing

pause
Can someone please tell me what I am doing wrong?

And out of interest sake, how will the code look for execution in linux?
Image
DarkRanger
Registered User
Posts: 8346
Joined: 10 May 2006, 02:00
Processor: Intel i5-3750
Motherboard: Gigabyte
Graphics card: nVidia GTX 550Ti
Memory: 8GB Jetram
Contact:

Re: Windows batch file issue

Post by DarkRanger »

Anyone?
Image
Post Reply