1.

Solve : help creating batch directory renamer?

Answer»

i'm working on a server that has some mac clients. unfortunately our end users OFTEN create files and folders with
-leading spaces
-trailing spaces
-trailing periods

for now if we can just create something that remedies the trailing period problem i think i'll be able to edit that to suit my other needs.

i would like to be able to point this to a directory.
have it scan the directory for any folders or files that end in "."
rename the said folders/files to ".dot"
and let me know when it's finished.


thanks in advance for any assitance providedThis little snippet is untested as I was unable to create a FILE or folder name with a trailing dot.

Code: [Select]@echo off
for /f "TOKENS=* delims=" %%i in ('dir drive:\path /s /b ^| findstr ".*\.$"') do (
if not errorlevel 1 ren "%%i" "%%~ni.dot"
)
echo Done! Done!! Done!!!

Hope this helps
Quote from: Sidewinder on November 25, 2008, 12:19:50 PM

This little snippet is untested as I was unable to create a file or folder name with a trailing dot.

Code: [Select]@echo off
for /f "tokens=* delims=" %%i in ('dir drive:\path /s /b ^| findstr ".*\.$"') do (
if not errorlevel 1 ren "%%i" "%%~ni.dot"
)
echo Done! Done!! Done!!!

Hope this helps




thanks for the help. i tried using this but it doesn't seem to be working, maybe i'm doing somethign wrong. the directories i'm working with are located here:

Code: [Select]D:\moved user folders\NICOLJ\Event Photography


so i modified your code to match that file location
Code: [Select]@echo off
for /f "tokens=* delims=" %%i in ('D:\movedu~1\NICOLJ\EventP~1 /s /b ^| findstr ".*\.$"') do (
ren "%%i" "%%~ni.dot"
)
echo Done




and this is what i get
Code: [Select]'D:\movedu~1\NICOLJ\EventP~1' is not recognized as an internal or external comma
nd,
operable program or batch file.
Done

any more suggestions? Quote
@echo off
for /f "tokens=* delims=" %%i in ('D:\movedu~1\NICOLJ\EventP~1 /s /b ^| findstr ".*\.$"') do (
ren "%%i" "%%~ni.dot"
)
echo Done

I believe you left out the dir command:

Code: [Select]@echo off
for /f "tokens=* delims=" %%i in ('dir D:\movedu~1\NICOLJ\EventP~1 /s /b ^| findstr ".*\.$"') do (
if not errorlevel 1 ren "%%i" "%%~ni.dot"
)
echo Done! Done!! Done!!!

As mentioned, this code is untested. How did your users manage to create files/folders with a trailing dot? I tried quotes and even Explorer, but had no luck.


Quote from: Sidewinder on November 25, 2008, 01:17:40 PM
Quote
@echo off
for /f "tokens=* delims=" %%i in ('D:\movedu~1\NICOLJ\EventP~1 /s /b ^| findstr ".*\.$"') do (
ren "%%i" "%%~ni.dot"
)
echo Done

I believe you left out the dir command:

Code: [Select]@echo off
for /f "tokens=* delims=" %%i in ('dir D:\movedu~1\NICOLJ\EventP~1 /s /b ^| findstr ".*\.$"') do (
if not errorlevel 1 ren "%%i" "%%~ni.dot"
)
echo Done! Done!! Done!!!

As mentioned, this code is untested. How did your users manage to create files/folders with a trailing dot? I tried quotes and even Explorer, but had no luck.





eh, i appriciate the help but that doesn't see to WORK either. the situation is; we have mac users that connect to the server to save files. they save the files with the problems and i[on the server end] find it difficult to work with the files afterwards Quote
i appriciate the help but that doesn't see to work either

How doesn't it work? Let's start simple and we can build this together. From the command prompt enter the following LINE and post the output (or at least some of it, if it's too lengthy):

dir D:\movedu~1\NICOLJ\EventP~1 /s /b | findstr ".*\.$"

Once we can see the output, we can build the rest of the command.



If it is possible, also post some of the input by running dir on the same directory.


Discussion

No Comment Found