batch script error

Archived From: Technology
  • Page :
  • 1
  • Text Only
rated:
Cannot figure out how to fix this script. Used it previously with no problem.

Now gives " was unexpected at this time".

Works if you extract the zip, then drop files into the folder...but not the other way around.



http://www.howtogeek.com/57661/stupid-geek-tricks-randomly-renam...

@ECHO OFF
ECHO Random Names
ECHO Written By: Jason Faulkner
ECHO HowToGeek.com
ECHO.
ECHO.

REM Randomly renames every file in a directory.

SETLOCAL EnableExtensions EnableDelayedExpansion

REM 0 = Rename the file randomly.
REM 1 = Prepend the existing file name with randomly generated string.
SET PrependOnly=0

REM 1 = Undo changes according to the translation file.
REM This will only work if the file "__Translation.txt" is in the same folder.
REM If you delete the translaction file, you will not be able to undo the changes!
SET Undo=0


REM --------------------------------------------------------------------------
REM Do not modify anything below this line unless you know what you are doing.
REM --------------------------------------------------------------------------

SET TranslationFile=__Translation.txt

IF NOT {%Undo%}=={1} (
	REM Rename files
	ECHO You are about to randomly rename every file in the following folder:
	ECHO %~dp0
	ECHO.
	ECHO A file named %TranslationFile% will be created which allows you to undo this.
	ECHO Warning: If %TranslationFile% is lost/deleted, this action cannot be undone.
	ECHO Type "OK" to continue.
	SET /P Confirm=
	IF /I NOT {!Confirm!}=={OK} (
		ECHO.
		ECHO Aborting.
		GOTO :EOF
	)

	ECHO Original Name/Random Name > %TranslationFile%
	ECHO ------------------------- >> %TranslationFile%

	FOR /F "tokens=*" %%A IN ('DIR /A:-D /B') DO (
		IF NOT %%A==%~nx0 (
			IF NOT %%A==%TranslationFile% (
				SET Use=%%~xA
				IF {%PrependOnly%}=={1} SET Use=_%%A
				
				SET NewName=!RANDOM!-!RANDOM!-!RANDOM!!Use!
				ECHO %%A/!NewName!>> %TranslationFile%
				
				RENAME "%%A" "!NewName!"
			)
		)
	)
) ELSE (
	ECHO Undo mode.
	IF NOT EXIST %TranslationFile% (
		ECHO Missing translation file: %TranslationFile%
		PAUSE
		GOTO :EOF
	)
	FOR /F "skip=2 tokens=1,2 delims=/" %%A IN (%TranslationFile%) DO RENAME "%%B" "%%A"
	DEL /F /Q %TranslationFile%
)

Member Summary
Thanks for visiting FatWallet.com. Join for free to remove this ad.

Diff your file against the original and see if there is any modification.

I tried the batch file and there was no error.

edit: typo

that was the original

it works when you drop files into the folder, then run the file, but not if you drop the file into a folder with the stuff you want to rename

Might be the permission problem?

v999 said:   Might be the permission problem?Yeah, that's my first thought too. Check the permissions on the files in that folder and the account you are trying to run the batch file from.

you might be right....tried on another computer and it worked fine


any suggestions as to fixing them?
had various things get out of wack so no telling at what point it "broke"

Easiest way is make new folder and drop it in there and see if it works. If it does, rename the old / new and you are good to go

but that doesn't make any sense....I tried it multiple times moving files back and forth, if it was just the folder it should have been fixed

Permissions have 3 types. The 'Folder There Type' and the 'Folder Above Type' and the 'Top Level Folder' (If I remember right)

Sometimes a parent folder is causing the problem so if a NEW folder fails, it might be higher up. That's why I said to make a new folder and check.



Disclaimer: By providing links to other sites, FatWallet.com does not guarantee, approve or endorse the information or products available at these sites, nor does a link indicate any association with or endorsement by the linked site to FatWallet.com.

Thanks for visiting FatWallet.com. Join for free to remove this ad.

TRUSTe online privacy certification

While FatWallet makes every effort to post correct information, offers are subject to change without notice.
Some exclusions may apply based upon merchant policies.
© 1999-2014