|
Answer» Hi Everyone I try to create small batch file that searches for files with the extension .xls, when it finds it, counting how many characters file has. If it has more then one it writes the file name to text file. Can somebody help me with this and tell me how I can run it.
All help is greatly appreciated.
Marcin Something like this?
Code: [Select]@echo off
rem Delete old log file if exist log.txt del log.txt
rem Loop over all XLS files in current folder and extract file names and sizes for /f "skip=5 tokens=3,4" %%a in ('DIR /a-d *.xls') do ( rem Ignore useless stuff also printed by 'dir' command if exist %%b ( rem Compare file size with zero if %%a equ 0 ( rem Write file name to log file echo %%b >> log.txt ) ) )
Cheers, [glb]cs[/glb]Hi Thank you so much for your response. I copy and paste it to the txt file with ext .bat. When I try to run it id doesn't create txt file. Can please tell me how to make it to work.
MarcinSave the code in a batch file (e.g. xls.bat) in the same directory as the XLS files are. Then call xls on the command line.
Are there any error messages? Which WINDOWS/DOS version are you using? Did you check if dir /a-d *.xls shows any files? Are you sure that any XLS file is empty (zero bytes)?
Cheers, [glb]cs[/glb]Hey
There are no error MSGS, all I do is to double clik on the batch file, but the dos flashes and doesn't do anything else and nothing else is created.
I am using Windows 2000 SP4 with all updates.
I am looking for excel files that are full, but I am not looking for the content of these files. I am looking for the number of file names caracters. So for example there is a file called Marcin_Tomczak_wants_to_go_to_Europe_ne xt_year.xls. So if I am looking for files where filename is longer then ...let say 40 characters long so this batch file should find this file insert it's name into the .txt file. So the filename I entered above contains 46 characters and therefore should be included into that list.
Thank you so much for your help and I am very greatfull.
Marcin
I thought, you would like to check the file size. For file names try something like this:
Code: [Select]@echo off
setlocal
set n=15
for %%i in (*.txt) do ( set v=%%i set w=!v:~0,%n%! if not !v!==!w! echo !v! too long ) n defines here the maximum number of characters (INCLUDING extension). Make sure, command extension and delayed expansion are enabled.
We are here close to the maximum you can achive with MS-DOS Consider changing to a "real" scripting language like Tcl, PERL or Python.
Cheers, [glb]cs[/glb]
|