for loop to get substring of filename
Posted: 02 Oct 2014 12:08
i have this small piece of code that is not working. basically i need to extract the filename without the extension and make it look like only the first 20 characters.
e.g.
sanbox_BULKLOAD_EXPORT.sql
output:
sanbox_BULKLOAD_EXPO
this is because the application interface when i will move the file only accepts 20 characters in the filename.
this is the code that is not working that i am using in a batch file sample4.bat:
these are the input:
this is the output when the sample4.bat is run:
please help. thank you.
e.g.
sanbox_BULKLOAD_EXPORT.sql
output:
sanbox_BULKLOAD_EXPO
this is because the application interface when i will move the file only accepts 20 characters in the filename.
this is the code that is not working that i am using in a batch file sample4.bat:
Code: Select all
cls
FOR %%i IN ("*.sql") DO (SET fn=%%~ni SET h=%fn:~1,20% echo %h)
these are the input:
Code: Select all
query01.sql
query02.sql
query03.sql
query04.sql
query04.~sql
query1.sql
query2.sql
query3.sql
query4.sql
sample4.bat
sanbox_BULKLOAD_EXPORT.sql
this is the output when the sample4.bat is run:
Code: Select all
R:\temp>(SET fn=final_flag_m123 SET h=anbox_BULKLOAD_EXPOR echo h )
R:\temp>(SET fn=fix_county_franklin SET h=anbox_BULKLOAD_EXPOR echo h )
R:\temp>(SET fn=query01 SET h=anbox_BULKLOAD_EXPOR echo h )
R:\temp>(SET fn=query02 SET h=anbox_BULKLOAD_EXPOR echo h )
R:\temp>(SET fn=query03 SET h=anbox_BULKLOAD_EXPOR echo h )
R:\temp>(SET fn=query04 SET h=anbox_BULKLOAD_EXPOR echo h )
R:\temp>(SET fn=query1 SET h=anbox_BULKLOAD_EXPOR echo h )
R:\temp>(SET fn=query2 SET h=anbox_BULKLOAD_EXPOR echo h )
R:\temp>(SET fn=query3 SET h=anbox_BULKLOAD_EXPOR echo h )
R:\temp>(SET fn=query4 SET h=anbox_BULKLOAD_EXPOR echo h )
R:\temp>(SET fn=sanbox_BULKLOAD_EXPORT SET h=anbox_BULKLOAD_EXPOR echo h )
please help. thank you.