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.
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 3 years ago.
Improve this question
I have a text file that contains gmail contacts, after each address there's the name of the email address owner example : John(at)gmail(dot)com:John and some other emails like this : John(at)gmail(dot)com;John
each address is in a new line, I want to delete all names and keep just the addresses, so I don't have to do it manually each time. how can I do this in batch script. I want to delete everything after ":" or ";" in every line. Thanks
It's a simple one-liner:
(FOR /f "delims=:;" %%a IN (filename1) DO ECHO %%a)>filename2
where filename* are your filenames and > should be replaced by >> to append to filename2 rather than creating filename2 anew.
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 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