Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Okay, so I need to take the first three letters of a file from a list of files, and place this into a text file in a certain manner. I will provide examples below.

Lets say that I have two file names in the same directory, one called cougar.txt and the other bear.txt. These are in the animals directory. I need to take the first three letters of these words, and transpose them into a text file along with the directory, in the following format:

BEA = "animals/bear.txt"

COU = "animals/cougar.txt"

This should happen with any random thing that might be in the list. I'm fairly new to this sort of coding, so I'm not quite sure which language to use, and I'm learning as I go. This new challenge seems fairly daunting to me, and I would be much appreciated if you guys could help.

Also, I'm using Windows 7. Been attempting at this all day, to no avail. Preferably done in batch, but if that is impossible I'm open to recommendations.

Current code: I don't think I'm really getting anywhere xD.

for /F "tokens=*" %%A in (#opm.txt) do set str=%%A
set str=%str:~0,3%
echo.%str% > #tags.txt

pause
share|improve this question

closed as off topic by Sathya Sep 11 '12 at 11:01

Questions on Super User are expected to relate to computer software or computer hardware within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Please do not crosspost, it's against the rules: meta.stackexchange.com/questions/64068/…. Close one or ask to migrate it –  wmz Sep 11 '12 at 9:05
    
Apologies, I figured this was a different website, should have guessed not, similar design. –  JuniorD Sep 11 '12 at 9:44
    
please don't crosspost –  Sathya Sep 11 '12 at 11:01
add comment

1 Answer

As you have already started I'm going to give you help on your specific issue (or you can post your code which means I can try to edit it for you).

Similar to the Left function in VB a batch script can return a specified number of characters from the left side of a string by specifying a substring for an expansion given a position of 0 and a length using :~ while expanding a variable content. The example shows how to return the first 4 characters of a string.

set str=cougar
set str=%str:~0,3%

The result will be 'cou'

Source

EDIT

You have already asked this question here. Why were these answers not good enough?

share|improve this answer
    
So could I potentially do this with a variable? –  JuniorD Sep 11 '12 at 9:50
    
Yes. Read each file in a loop and assign the file name to a variable, use the code above to create the string value. The answer you've got on Stack Overflow seem to cover this and do what you're after though. –  Dave Rook Sep 11 '12 at 9:53
    
I attempted to use those but they didn't appear to work. –  JuniorD Sep 11 '12 at 10:01
    
I suggest you close a post first. –  Dave Rook Sep 11 '12 at 10:03
    
It appears it won't let me. I was completely unaware that crossposting was an issue. –  JuniorD Sep 11 '12 at 10:11
show 2 more comments

Not the answer you're looking for? Browse other questions tagged or ask your own question.