Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

File Creating BAT file


  • Please log in to reply
5 replies to this topic

#1 SammiD

SammiD

  • Members
  • 7 posts
  • OFFLINE
  •  
  • Local time:01:19 AM

Posted 24 April 2014 - 01:08 PM

I am an  looking for assistance with BAT file writing. I have a list of what we call Driver ID codes. I saved them in a text file called Test.txt located on the desktop (Some of the IDs listed below)

AARCOX
AARSLI
ABAEST
ABATMO
ABDISS
ABDMHD
ABDSHO
ABDUJE
ABEEDD

 

I am trying to write a .bat file to convert those IDs into a file (.file not folder) and save it in a folder on the desktop called "CREngland Driver IDs"

 

I have attached a snap shot image of what i want

Thanks!

Attached Files


Edited by hamluis, 24 April 2014 - 01:19 PM.
Moved from Win 7 to Programming - Hamluis.


BC AdBot (Login to Remove)

 


#2 whoabuddy

whoabuddy

    Bleepin' Verbose


  • Malware Response Instructor
  • 2,053 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Cottonwood, AZ
  • Local time:09:19 PM

Posted 24 April 2014 - 02:21 PM

Hello SammiD,

It looks like you can achieve what you want to do using a for loop, an example of the code is below:
for /F "tokens=*" %%A in (FILENAME.txt) do ACTION
The code above will take each line from the text file FILENAME.txt and process it according to the ACTION line. Using this info we can build a batch file; you can copy and paste the contents below into a file, click File > Save As..., enter DriverIDs.bat as the file name, select File Type: All Files, then click Ok to save.
@echo off
:: Batch file created for SammiD
:: example of for loop to read text file
:: created by whoabuddy 04242014
:: requires DriverIDs text file
for /F "tokens=*" %%A in (DriverIDs.txt) do nul >%%A.file
Now save your text file with driver file names as DriverIDs.txt (note the upper/lower case!), DriverIDs.bat and DriverIDs.txt need to be in the directory where youwant to create files. When you double-click on DriverIDs.bat it will look through the contents of DriverIDs.txt and create a 0-byte (NUL) file based on each one. I used the following DriverIDs.txt as a test:
AA
BB
CC
DD
EEEE
FFFF
GGGG
HHHH
IIIIII
JJJJJJ
KKKKKKKK
LLLLLLLL
MNOPQRTS
UVWXYZZZ
Running the batch file from my Windows 8.1 VM creates the files as expected, however it also asked me what program I wanted to use to open them although nothing actually happened. Hopefully this information will help you complete your task!

04242014_SammiD_BatchExample.png

Best Regards,
whoabuddy

References:
http://stackoverflow.com/questions/155932/how-do-you-loop-through-each-line-in-a-text-file-using-a-windows-batch-file
http://technet.microsoft.com/en-us/library/bb490909.aspx

Meditate. Elevate. Appreciate. | "Life is a journey, love is the destination, happiness is the path!"
If I am helping you and have not responded within 48 hours, please send me a PM.
Vi Veri Universum Vivus Vici (VVVVV)
Excellent Security Advice
Proud member of UNITE

#3 SammiD

SammiD
  • Topic Starter

  • Members
  • 7 posts
  • OFFLINE
  •  
  • Local time:01:19 AM

Posted 24 April 2014 - 02:54 PM

Thanks Whoabuddy,
This was really helpful. But i keep getting a Windows Security prompt every time it creates a file. Do i have to change a security setting on my computer?
 
 
This is the message i get...
 
It says These files can't be opened
Your Internet Security settings prevented one or more files from being opened



#4 whoabuddy

whoabuddy

    Bleepin' Verbose


  • Malware Response Instructor
  • 2,053 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Cottonwood, AZ
  • Local time:09:19 PM

Posted 24 April 2014 - 03:03 PM

Hi SammiD,

That sounds similar to the issue I was having when I tested it, instead of using "NUL > name.file" let's try using fsutil.
@echo off
:: Batch file created for SammiD
:: example of for loop to read text file
:: created by whoabuddy 04242014
:: requires DriverIDs text file
:: using fsutil instead of nul for output
for /F "tokens=*" %%A in (DriverIDs.txt) do fsutil file createnew %%A.file 0 >NUL
This worked better in my tests, do you still receive a security prompt?

Best Regards,
whoabuddy
Meditate. Elevate. Appreciate. | "Life is a journey, love is the destination, happiness is the path!"
If I am helping you and have not responded within 48 hours, please send me a PM.
Vi Veri Universum Vivus Vici (VVVVV)
Excellent Security Advice
Proud member of UNITE

#5 SammiD

SammiD
  • Topic Starter

  • Members
  • 7 posts
  • OFFLINE
  •  
  • Local time:01:19 AM

Posted 24 April 2014 - 03:22 PM

YES!!

That work perfectly... Thanks for your help Whoabuddy!



#6 whoabuddy

whoabuddy

    Bleepin' Verbose


  • Malware Response Instructor
  • 2,053 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Cottonwood, AZ
  • Local time:09:19 PM

Posted 24 April 2014 - 03:45 PM

Hi SammiD,

No problem, I am happy to help!

Best Regards,
whoabuddy
Meditate. Elevate. Appreciate. | "Life is a journey, love is the destination, happiness is the path!"
If I am helping you and have not responded within 48 hours, please send me a PM.
Vi Veri Universum Vivus Vici (VVVVV)
Excellent Security Advice
Proud member of UNITE




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users