0

There are 11 Webservices inside service_ccsl.txt After I am done with my work to make this text file handier instead of going and deleting manually, I'd like to integrate this Job in Jenkins task. Please, suggest me a way. Thanks in advance.

Jan B.
  • 6,030
  • 5
  • 32
  • 53
Pavan
  • 11
  • 6
  • [Equivalent of Linux `touch` to create an empty file with PowerShell?](https://superuser.com/q/502374/241386), [Windows equivalent of the Linux command 'touch'?](https://superuser.com/q/10426/241386) – phuclv Sep 20 '17 at 13:06
  • 1
    Possible duplicate of [Windows equivalent of 'touch' (i.e. the node.js way to create an index.html)](https://stackoverflow.com/questions/30011267/windows-equivalent-of-touch-i-e-the-node-js-way-to-create-an-index-html) – phuclv Sep 20 '17 at 13:06

2 Answers2

2

probably the easiest methods:

type nul > service_ccsl.txt

or

break > service_ccsl.txt

or

echo. 2> service_ccsl.txt

as for a for loop:

@echo off
for %%f in (c:\test\*_ccsl.*) do echo type nul > %%f

The above example will loop through all files in C:\test and find anything that contains _ccsl. so it will match service_ccsl.txt test_ccsl.txt anything_ccsl.exe but it will not match service_ccsl_all.txt for instance.

You can play with the wildcards to fine tune your scenario, once you are happy your are confident, then remove the echo portion from the above piece of code.

This one will set the readonly attribute on for all files ending with _all.txt then we nul the files, access will be denied for the _all.txt files the rest will be nulled, then we disable the readonly attribute.

@echo off
attrib +r "c:\test\*_all.txt"
for %%f in (c:\test\service*.txt) do type nul > %%f
attrib -r "c:\test\*_all.txt"

Note, that if you echo this, it will still echo the all.txt files as they are still readable, but the nul will not affect these files.

Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • Cheers Barnard, this worked very well. @echo off null>"C:\Users\IBM_ADMIN\Desktop\New folder (2)\service_td.txt" pause if I'd like to delete 11 service_*.txt files at once. Is that possible through one batch file? I have 11 functional groups and I'll be working with different functional groups at once based on requirements. I will be updating service_*.txt files upon requirement. Is it possible to have a common batch file to clear the contents of all text files though I update them or not? Just FYI I have both service_*_all.txt & service_*.txt files, Idl to clean up later. – Pavan Sep 20 '17 at 09:35
  • Yes, you just need to run a for loop. are all the files in 1 directory? are there any other files in that directory? – Gerhard Sep 20 '17 at 09:38
  • there are 3 folders, few XSD files, ant file, JAR file and XML files. This folder is a combo. – Pavan Sep 20 '17 at 09:41
  • So all the TXT files in those folders your want to nul? – Gerhard Sep 20 '17 at 09:44
  • yeah Bernard for an example : instead of service_ccsl_all.txt I'd like to null service_ccsl.txt file. So, I have 11 functional goups in total like this, ccsl,td,fx,gl, etc.. is there any chance to apply condition where it picks up service_ccsl.txt file instead of service_ccsl_all.txt file. – Pavan Sep 20 '17 at 09:49
  • Thanks for the useful info Bernard. Is there a way to give ccsl as a wildcard or a variable as it varies in runtime. How about giving service_A.txt where 'A' as a variable which depicts ccsl, gl, td, retail, etc 11 functional groups. – Pavan Sep 20 '17 at 11:19
  • I tried this way it cleaned all 11 text files but am also looking is there any other way which is worth knowing. @echo off null>"C:\Users\IBM_ADMIN\Desktop\New folder (2)\service_ccsl.txt" null>"C:\Users\IBM_ADMIN\Desktop\New folder (2)\service_cif.txt" null>"C:\Users\IBM_ADMIN\Desktop\New folder (2)\service_dlrtxn.txt" null>"C:\Users\IBM_ADMIN\Desktop\New folder (2)\service_gl.txt" null>"C:\Users\IBM_ADMIN\Desktop\New folder (2)\service_fx.txt" null>"C:\Users\IBM_ADMIN\Desktop\New folder (2)\service_iap.txt" pause – Pavan Sep 20 '17 at 11:19
  • I don't understand the requirement? It worked, but what are you asking additionally? – Gerhard Sep 20 '17 at 11:21
  • No problem, but explain to me what else you meant with the previous comment and I will try and help, I am just uncertain of your requirement. – Gerhard Sep 20 '17 at 11:25
  • do you mean doing something like `for %%f in (c:\test\service_*.txt ) do type nul > %%f` – Gerhard Sep 20 '17 at 11:27
  • It worked for sure. am just curious to know any alternate approach for this method. yeah, something like this in one line Barnard. for %%f in (c:\test\service_*.txt ) do type nul > %%f – Pavan Sep 20 '17 at 11:29
0

You can use break to erase all the contents of a file using batch script.

break>\path\to\service_ccsl.txt

You can add the above command in Execute windows batch script step in Build section of your job in Jenkins.

ANIL
  • 2,542
  • 4
  • 25
  • 44
  • Cheers ANIL for the info if I'd like to delete 11 service_*.txt files at once. Is that possible through one batch file? I have 11 functional groups and I'll be working with different functional groups at once based on requirements. I will be updating service_*.txt files upon requirement. Is it possible to have a common batch file to clear the contents of all text files though I update them or not? Just FYI I have both service_*_all.txt & service_*.txt files, I'd like to clean up later. – Pavan Sep 20 '17 at 09:35