| 1. |
Solve : Changing file extension case? |
|
Answer» From a batch script, how do I change all specific file extension combinations to all lower case The OP is trying to avoid changing the .CSV2 extension. I suppose a little modification can take care of that: No modification needed. The OP's requirement is catered for. The *.csv filespec will only find files with the extension (any case, upper lower or a mixture) ".csv" that is, a dot and the three characters (only) c , s and v - to include .csv2 it would have to be *.csv* or *.csv? Before: Code: [Select]C:\Users\Test>dir *.csv* Volume in drive C is Win07 Volume Serial Number is E4DB-A92A Directory of C:\Users\Test 15/11/2011 18:30 16 animals.CsV 12/11/2011 10:05 44 Myquotes.cSv 11/11/2011 06:59 23 quotes.cSV 12/11/2011 10:01 525 test.CSV 15/11/2011 19:01 12 test.CSV2 15/11/2011 19:01 12 testxxx.CSV2 6 File(s) 632 bytes 0 Dir(s) 26,632,110,080 bytes free After: Code: [Select]C:\Users\Test>dir *.cs* Volume in drive C is Win07 Volume Serial Number is E4DB-A92A Directory of C:\Users\Test 15/11/2011 18:30 16 animals.csv 12/11/2011 10:05 44 Myquotes.csv 11/11/2011 06:59 23 quotes.csv 12/11/2011 10:01 525 test.csv 15/11/2011 19:01 12 test.CSV2 15/11/2011 19:01 12 testxxx.CSV2 6 File(s) 632 bytes 0 Dir(s) 26,632,110,080 bytes free Hmmm... Maybe my cmd prompt is different than yours. When I run dir *.csv I get all of the .csv2 extensions as well. Code: [Select]Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\Raven\Desktop\Code\Batch\Test>dir *.csv Volume in drive C is OSDisk Volume Serial Number is 008C-D47E Directory of C:\Users\Raven\Desktop\Code\Batch\Test 11/15/2011 10:18 AM 0 New.csv 11/15/2011 10:18 AM 0 New2.csv2 11/15/2011 10:18 AM 0 New3.csv2 11/15/2011 10:18 AM 0 New4.csV 4 File(s) 0 bytes 0 Dir(s) 193,769,201,664 bytes free odd... Windows 7 SP1 (64 bit, 64 bit command prompt) (Edit - the result is the same with 32 bit command prompt) 64 bit command prompt: %windir%\System32\cmd.exe 32 bit command prompt: %windir%\SysWoW64\cmd.exe Code: [Select]Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. c:\Users\test>dir *.csv Volume in drive C is Win07 Volume Serial Number is E4DB-A92A Directory of c:\Users\test 15/11/2011 18:30 16 animals.csv 12/11/2011 10:05 44 Myquotes.csv 11/11/2011 06:59 23 quotes.csv 12/11/2011 10:01 525 test.csv 4 File(s) 608 bytes 0 Dir(s) 26,631,081,984 bytes free c:\Users\test>dir *.csv* Volume in drive C is Win07 Volume Serial Number is E4DB-A92A Directory of c:\Users\test 15/11/2011 18:30 16 animals.csv 12/11/2011 10:05 44 Myquotes.csv 11/11/2011 06:59 23 quotes.csv 12/11/2011 10:01 525 test.csv 15/11/2011 19:01 12 test.CSV2 15/11/2011 19:01 12 testxxx.CSV2 6 File(s) 632 bytes 0 Dir(s) 26,631,081,984 bytes free Is your Windows 7 32 or 64 bit? Very weird. I run a 32-bit Win7 environment. That may need to be researched as to why that little anomoly is happening. To et_phonehome_2: The solution to your exact issue may vary depending on the OS you are running. I suggest opening your cmd prompt and going to the directory these files are in and typing dir *.csv If you see .csv2 extensions, use my code, if not, use Salmon Trout's.I thought it might be to do with the filesystem having short-filename creation enabled on your system and disabled on mine, but I checked and it is enabled on mine. This is going to BUG me until I find out what is going on... [Update] I have done a bit of Googling, and it seems that there is a bug in Win32 wildcard expansion, when the wildcard has exactly 3 chars e.g. *.csv - it finds all the .csv and then all the csv2 csvNNNN etc. I am going to do some checking in XP 32 bit. [Edit] There ya go... Code: [Select]Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\Documents and Settings\Administrator\test>dir *.csv Volume in drive C has no label. Volume Serial Number is 24FE-A31E Directory of C:\Documents and Settings\Administrator\test 15/11/2011 09:16 PM 8 test.CSV 15/11/2011 09:17 PM 8 test.csv2 15/11/2011 09:17 PM 8 test1.CSV 15/11/2011 09:17 PM 8 test1.csv2 15/11/2011 09:20 PM 8 test1.csvN1 15/11/2011 09:20 PM 8 test1.csvN2 15/11/2011 09:20 PM 8 test1.csvN3 15/11/2011 09:20 PM 8 test1.csvN4 15/11/2011 09:17 PM 8 test2.CSV 15/11/2011 09:18 PM 8 test2.csv2 15/11/2011 09:17 PM 8 test3.CSV 15/11/2011 09:18 PM 8 test3.csv2 12 File(s) 96 bytes 0 Dir(s) 132,692,742,144 bytes free C:\Documents and Settings\Administrator\test>dir *.csvN* Volume in drive C has no label. Volume Serial Number is 24FE-A31E Directory of C:\Documents and Settings\Administrator\test 15/11/2011 09:20 PM 8 test1.csvN1 15/11/2011 09:20 PM 8 test1.csvN2 15/11/2011 09:20 PM 8 test1.csvN3 15/11/2011 09:20 PM 8 test1.csvN4 4 File(s) 32 bytes 0 Dir(s) 132,692,742,144 bytes free So I believe your check (that the extension is just ".csv" and no longer) is vital for compatibility with all Windows versions. dir /x shows short filenames generated for non- 8-dot-3 compatible filenames. They have .csv extensions thus win32 finds them and matches the wildcard. Code: [Select]C:\Documents and Settings\Administrator\test>dir /x Volume in drive C has no label. Volume Serial Number is 24FE-A31E Directory of C:\Documents and Settings\Administrator\test 15/11/2011 09:20 PM <DIR> . 15/11/2011 09:20 PM <DIR> .. 15/11/2011 09:16 PM 8 test.CSV 15/11/2011 09:17 PM 8 TEST~1.CSV test.csv2 15/11/2011 09:17 PM 8 test1.CSV 15/11/2011 09:17 PM 8 TEST1~1.CSV test1.csv2 15/11/2011 09:20 PM 8 TEST1~2.CSV test1.csvN1 15/11/2011 09:20 PM 8 TEST1~3.CSV test1.csvN2 15/11/2011 09:20 PM 8 TEST1~4.CSV test1.csvN3 15/11/2011 09:20 PM 8 TE3013~1.CSV test1.csvN4 15/11/2011 09:17 PM 8 test2.CSV 15/11/2011 09:18 PM 8 TEST2~1.CSV test2.csv2 15/11/2011 09:17 PM 8 test3.CSV 15/11/2011 09:18 PM 8 TEST3~1.CSV test3.csv2So more than likely, my system is searching the 8-dot-3 filenames in which case any extension starting with .csv shows up. That's a weird bug. Wonder if they are planning to patch that, or if I'm just out of date with the updates and patches. |
|