Hey,
I am working on a project for the guys at xda-developers. I need help with one part of it, I've been at this part all day and have come up with nothing.
I have a txt file with a variable amount of lines in a certain directory that I want to read each line
(each line has no spaces, just a list of files, ie
com.htc.bookmarks.apk
WifiRouter.apk
*.*
and so on
)
I need to be able to grab all of these lines, store each line in a separate variable (a single letter),
echo something like this:
A. com.htc.bookmarks.apk
B. WifiRouter.apk
C. *.*
and so on
and then I'm going to have:
set /P choice=What Letter?
and depending on what letter they choose, it will delete that file from a certain directory.
So if they choose "A"
it will
del "%CD%\blah\blah\com.htc.bookmarks.apk"
As I'm typing this, I'm realizing that this probably isn't possible lol
Can I get any help?
Set multiple lines from file.txt to variables and Echo them
Moderator: DosItHelp
-
- Posts: 4
- Joined: 26 Mar 2010 14:25
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: Set multiple lines from file.txt to variables and Echo t
regaw_leinad wrote:As I'm typing this, I'm realizing that this probably isn't possible lol
yes its possible with batch/vbscript. But i offer an alternative solution.
If you have no restriction on the language used, here's Python script you can try
Code: Select all
import sys
import os
inputfile=sys.argv[1]
certain_directory=os.path.join("c:\\","path")
choices={}
for n,line in enumerate(open(inputfile)):
choices[str(n+1)]=line.rstrip()
for k in sorted(choices.keys()):
print k , "->", choices[k]
c=raw_input("Which one to delete ?" )
delete_file=os.path.join(certain_directory,choices[c])
d=raw_input("Delete %s [yn]? "% delete_file )
if d.lower() in ['yes','y']:
try:
os.remove(delete_file)
except OSError,e:
print e
else:
print "remove ok"
save as myscript.py and on command line
Code: Select all
c:\test> python myscript.py myfile
-
- Posts: 4
- Joined: 26 Mar 2010 14:25
Re: Set multiple lines from file.txt to variables and Echo t
I do see what you mean with that one, but unfortunately, this is one small part of my program, that is all in batch. I just can't figure out for the life of me how to code it!