Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am working on a big project. When a user double clicks on a file with a certain file extension it opens it with a batch and checks the file for certain keywords.
I am not asking for people to type up the code for me. I just want to know how to set a default program for a file to a batch script and then have that batch script do something with the contents of the file. How do I do this?
Depending on your windows version you should be able to:
Right click the file
Choose open with
Choose choose another app
Choose More Apps
Scroll to the bottom and Look for another app on this pc.
Select your file.
To do it via the command line (you'll need an elevated one).
ASSOC .ttt=TTTHandler
FTYPE TTTHandler=c:\temp\openttt2.bat "%1"
This will associate the batch file c:\temp\openttt2.bat with the .ttt extension.
Contents of my openttt2.bat test file:
echo Hello from ttt file opener. File passed = %1
pause
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to create 100 txt files starting from txt1 to txt100 with string data (i.e not to create an empty file) and it's doesn't matter if the data duplicate or not, I've just wanted to add some data in each file created in a specific path, so how can I do that?
We need a little bit more info such as what is going in the files and what name do you need for the files.
Give this a go as a start. It should create 100 files in C:\temp named as MyFile_1.txt through to MyFile_100.txt and each would contain the text Your Contents Here
#echo off
setlocal
set "txtpath=C:\temp\"
for /L %%a in (1,1,100) do >>%txtpath%MyFile_%%a.txt echo Your Contents Here
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm trying to make a batch file that will read a text file (Net.txt) to pull a datapath from it. Assign it to a variable then empty a file from a nearby location.
Net.txt looks like
SharedPath=C:\Program\2017\
SharedUNC=C:\Program\2017\
Then find the directory and delete files with a specific extension.
cd %variable%\OPTION\trash
DEL *.xxx
This works great locally when everything is on C: but I don't think batch/cmd supports UNC paths. Is there a better language to use?
To read a file line by line, use a for /f loop.
The following code assumes net.txt to be exactly as shown in your question and will delete the files in both the SharedPath and the SharedUNC (should they differ; if they are the same, del will spit an error for the second one (which you can suppress with 2>nul))
for /f "tokens=2 delims==" %%a in (net.txt) do del "%%aOPTION\trash\*.xxx"
If that is not what you want, please describe your problem in more detail.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a batch of PDF files in a folder and I am trying to rename them.
Example:
File1_20170501_data.pdf
File2_20170401_statistics.pdf
Sale2_20170404_Misc.pdf
I only want to keep the first six characters of each file name (the five characters left to underscore and the underscore) and replace everything behind with sample data.
The final file names should be:
File1_sample data.pdf
File2_sample data.pdf
Sale2_sample data.pdf
Anyone can advice which command line to use for this file renaming task?
Given your provided information at the time of this answer, one simple command should do what you need:
Ren "C:\path to\a folder\?????_*.pdf" "?????_sample data.pdf"
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm newbie in batch script. How to write a script on copying specific file from a network folder to my drive D:\
Example:
The filename is ABC021318X.zip, where 021318 is a date while ABC and X are constants. When the script is running it will prompt user to enter the date with a format of mm/dd/yy, then when I hit Enter, it will copy ABC(specified date)X.zip from a network folder to D: drive
Further, when file is not found, it will give a message:
FILE NOT FOUND!
Hoping someone with the relevant knowledge can help me out.
Thanks in advance.
Simply do:
#echo off
set /p "mydate=Please Enter date (MMddYY) : "
set "mydate=%mydate:/=%"
copy /Y Z:\AB%mydate%X.zip D:\
Where Z:\ is the network drive in this case.
Note, in this case users can add the date as MMddYY i.e 021418 or MM/dd/YY i.e 02/14/18 as it will strip out / if it exists.
Automatically, if file is not found, it will print error
The system cannot find the file specified.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am making a mock operating system using .bat files and I want to be able to create and write to .txt files so I can store data, but I can't find a command that lets me do this. Any suggestions?
If want to export loggs to a txt file do something like
echo This text must be logged > log.txt
if you open log.txt after it:
This text must be logged
if you want to write in the next line or want to use a existing file,
use this
echo Next Line pls >> log.txt
so the updated log.text file looks like this
This text must be logged
Next Line pls
If you want to write text into the txt file with more lines than try this:
(
echo.This is line 1
echo.This is line 2
echo.This is line 3
echo.This is line 4
echo.
echo.^:^)
) > ".\yourfilename.txt"
"yourfilename.txt"
This is line 1
This is line 2
This is line 3
This is line 4
:)