Solved

Rename files which contain specific data

Posted on 2013-11-27
5
365 Views
Last Modified: 2013-12-02
I have a script which will look for specific data.
When it finds the specific data, it will create a separate file for each instance of that data found.

What I want to do is to be able to rename the newly created files based on criteria.

The bat file newscript.bat runs the split.vbs and then runs other commands.

The newscript.bat looks similar to this:

cscript.exe split.vbs


pushd "C:\Users\user\Desktop\Files"

if exist *.edi findstr "1234" *.ed >>test.txt || del test.txt
if exist *.edi findstr "5678" *.ed >>test2.txt || del test2.txt
if exist *.edi findstr "9101112" *.ed >>test3.txt || del test3.txt

popd



The split.vbs looks like this:

Set fso = CreateObject("Scripting.FileSystemObject")

data = Split(fso.OpenTextFile("output.txt").ReadAll, "IBA*00*")
For i = 1 To UBound(data)
  fso.OpenTextFile("new" & i & ".ed", 2, True).Write "IBA*00*" & data(i)
Next

 
What I would like to do is instead of:
if exist *.edi findstr "1234" *.ed >>test.txt || del test.txt

I would like to instruct it so do something similar to this:

if exist *.ed findstr "1234" *.ed ... then just rename the file that you found the "1234" in as
importantfile.ed

and instead of:

if exist *.ed findstr "5678" *.ed >>test2.txt || del test2.txt
I would like to instruct it to do something similar to this:
if exist *.ed findstr "5678" *.ed ... then just rename the file that you found the "5678" in as
anotherfilename.ed
0
Comment
Question by:100questions
  • 4
5 Comments
 
LVL 3

Expert Comment

by:telczj9
Comment Utility
Are you expecting to find "5678" in only one file or multiple files?

If it is multiple files how would you like to rename the extra occurrences?

Cheers!
0
 

Author Comment

by:100questions
Comment Utility
I am expecting to find "5678" only in 1 file.
0
 

Accepted Solution

by:
100questions earned 0 total points
Comment Utility
setlocal enabledelayedexpansion

for %%a in (C:\Temp\*.txt) do (
  find "prov1" "%%~fa" && ren "%%~fa" newfile1.txt
  find "prov2" "%%~fa" && ren "%%~fa" newfile2.txt
  find "prov3" "%%~fa" && ren "%%~fa" newfile3.txt
  find "prov4" "%%~fa" && ren "%%~fa" newfile4.txt
)
0
 

Author Comment

by:100questions
Comment Utility
The script works but it does not loop through any multiple files.  I need a more complete script.
0
 

Author Closing Comment

by:100questions
Comment Utility
Worked for me.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now