Computing.Net > Forums > Disk Operating System > Parsing filenames to variables

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Parsing filenames to variables

Reply to Message Icon

Name: Igor
Date: November 11, 2003 at 06:56:20 Pacific
OS: Windows 2000
CPU/Ram: PIII/256Mb
Comment:

My request is related to a previous subject on this list ("listing files and dates"), but I cannot figure out how to realise my script.

I need filenames to be parsed as an input to command-line. Here's an example:

a) My script does an ftp-"mget" and retrieves several files, sometimes 2 files, next time maybe 5 files, never more that 10 files.

b) The files have different filenames, at random. i.e. file_oo1.txt and file_102.txt

c) I need to process file 'file_001.txt' in a commandline statement. After this has finished, I need to process next file 'file_102.txt' in a similar commandline statement. The files will be moved away from their directory after processing each statement.

Does anybody have a suggestion how to set this up??? This would be a great help!



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: November 11, 2003 at 07:20:53 Pacific
Reply:

Based on the info you gave (not full clear to me) I show you the following sample as a basis to work around

@Echo Off

:: FProc.bat Syntax: FProc Folder_In Folder_Out

For /F "tokens=*" %%A in ('Dir /B /A:-D %1') Do (
Echo CommandLine %%~fA
Echo Move "%%~fA" "%2")

That script processes all the file stored in the %1 folder and then moves them to the %2 folder, i.e. FProc Folder_In Folder_Out.

I assume your ftp loads the desidered files into a specific folder where they are processed from. The script only echoes the supposed commands, as it is intended to be a sample.

I hope I have understood your need.


0

Response Number 2
Name: Igor
Date: November 11, 2003 at 07:25:05 Pacific
Reply:

I have found the 'almost' solution to my request above in the post titeled: "batch file - reading filename", except I do not need the full list, only 1st filename in the list.


0

Response Number 3
Name: Igor
Date: November 11, 2003 at 08:05:33 Pacific
Reply:

Hi Ivo,

Your solution is great!!!

However, the variabele "%%~fA" shows directory AND filename, how can I change this to show filename ONLY???

Thanks alot!!!

(I wish, I understood the 'tokens=' options much better than I do now....)

Igor.


0

Response Number 4
Name: IVO
Date: November 11, 2003 at 08:14:38 Pacific
Reply:

Use plain %%A instead of %%~fA; ~f means Full PathName and I typed that believing it simplifies the setup of command line. If you need more support post again.


0

Response Number 5
Name: Igor
Date: November 11, 2003 at 08:44:45 Pacific
Reply:

Hi IVO,

Many thanks! Very helpful and it does exactly what I want now. Will be using this for soooooo many more scripts in (near)future!

Do you maybe have a good web-source to study the possibilities of 'tokens' (besides the built-in help which is quite extensive but a tad too difficult for me to understand).

Have a nice day,
Igor.


0

Related Posts

See More



Response Number 6
Name: IVO
Date: November 11, 2003 at 09:26:53 Pacific
Reply:

Sorry, but I got my know how just reading the in-famous on-line help. Many people is looking for such a source of knowledge, but that seems to be like the Holy Graal. May be a day I may write a book on scripting, but I think that is a loser enterprise as nobody will buy a so tedious book...

Anyway tokens are piece of text strings separated by delimiters (single characters) as . , ; / $ or whatever you like. The standard delimiter is the space (blank) that can be overwritten by declaring delims explicitly.
Next step is to relate variables to tokens to be able to catch them, so the string:

My girl was born 12-3-1983 (nice day)

using %%A as explicit variable leads to

"tokens=1,2,3" A=My B=girl C=was
"tokens=1,2,3 delims=-" A=12 B=3 C=1983
"tokens=1,2,7 delims= -" A=My B=girl C=1983

the "wild" token * means all the balance after, so

"tokens=*" A=My girl was born 12-3....
"tokens=3*" A=was B=born 12-3-1983 (nice day)

to catch "nice day" you have to type

"tokens=2 delims=()" A=nice day

As you see the first token set by typing its position (1,2,3 and so on) is related to an alphabetic variables starting with the one explicity stated, %%A in the example (beware A is different from A). Delimiter is lost by itself.

I hope this helps you, but it is only a taste and sorry for my raw english.

Good work


0

Sponsored Link
Ads by Google
Reply to Message Icon

Extract date to find late... Batch Execute



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Parsing filenames to variables

Assigning values to variables (Please help) www.computing.net/answers/dos/assigning-values-to-variables-please-help/3851.html

How to store current path to variable? www.computing.net/answers/dos/how-to-store-current-path-to-variable/10943.html

Reading text from to variable www.computing.net/answers/dos/reading-text-from-to-variable/15549.html