Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We host Macintosh files on our Windows 2008 servers. They have files like

somegraphic.eps
._somegraphics.eps (hidden)

Many times our users will add non-standard characters to the files, like bullets and spaces at the end of the file names. It allows them to add the characters, but it won't let them alter the file names once they click enter.

Two questions:

  1. In a batch file, how could you get a list of all files ending in a space?
  2. In a batch file, how could you mass rename all files removing unwanted characters?

For that matter:

  1. How could you get a list of all files on a system, their modified times, and in an XML or easily data import format?

Discussion:

I try to rename with a dir/x filename, but the hidden properties seem to stop that from working.

Usually, I do a dir/b/s to get a full directory search in a bare format, but it doesn't include modified times.

share|improve this question
    
I think it's probably beyond the capabilities of CMD batch files, but would probably be relatively straightforward in Powershell. Would that be an option for you? –  Dennis Williamson Jan 21 '11 at 19:45
    
Can you create a file with a space at the end on demand? –  RobW Feb 4 '11 at 1:27

1 Answer 1

up vote 1 down vote accepted

Create a file with a space at the end:

echo Foo >  "\\?\c:\rcs\boo.txt "

List files on system in a batch file with modified date and bare listing:

for /f "tokens=*" %%A in ('dir /s/b %target%') do @echo %%~tA,"%%~A"

For example, a directory with three files including "boo.txt " looks like:

, "C:\rcs\boo.txt "
02/03/2011 17:48, "C:\rcs\foo1.txt"
02/03/2011 17:47, "C:\rcs\foo2.txt"

Note how the file date is missing. This could be your clue that the file name is illegal.

Take a look at filelist.exe from [http://www.jam-software.com/freeware/]. This program creates an expanded listing (many more data points) but doesnt balk at attributes like date.

Deleting is easy, renaming is harder.

The following tool renamed "boo.txt " to boo.txt

http://wren.adoxa.cjb.net

wren.exe boo~1.txt boo.txt

took care of the filename.

Note: Wren appears to have a 16 and 32 bit versions - I used the 16 bit one to perform the rename, and was constrained to renaming it to a 8.3 filename. You should be able to work around this.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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