You are not logged in.

#1 08 Jul 2015 15:29

NETWolF
New Member
Registered: 08 Jul 2015
Posts: 2

Get Random Folder name and write it as %FolderName%

On each PC I have one folder:
"C:\DIR\Photo_Random-String"
and need a script that will check this whole name [Photo and Random String]  and write it as %FolderName%.

I have very simple script:

C:
cd\
cd DIR
for /d %a in (Photo*) do (>nul 2>nul dir /a-d "%a\*.txt" && (set FOLDERNAME=%a))
IF EXIST %FOLDERNAME% CD %FOLDERNAME%
DEL /q *.jpg
CD..
RD %FOLDERNAME%
PAUSE

but give back this error:

   

"a*.txt" && (set FOLDERNAME=a)) was unexpected at this time."

What is wrong in this simple script? Or You have another idea to solve this?

Offline

#2 11 Jul 2015 21:21

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: Get Random Folder name and write it as %FolderName%

Unlike at the command like, when used in a script, "%a" must take the form "%%a".


cmd | *sh | ruby | chef

Offline

#3 13 Jul 2015 19:19

NETWolF
New Member
Registered: 08 Jul 2015
Posts: 2

Re: Get Random Folder name and write it as %FolderName%

I finally solved this  big_smile
This is working ver:

C:
CD\
CD DIR
IF EXIST FOTO_* (CD FOTO_*) ELSE (goto END)
FOR %%I IN (.) DO SET FOLDERNAME=%%~nI%%~xI
CD\
ECHO %FOLDERNAME% Exist - Delete it !
RD /q %FOLDERNAME%
PAUSE
END
Exit

Offline

#4 13 Jul 2015 20:37

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: Get Random Folder name and write it as %FolderName%

NETWolF wrote:

On each PC I have one folder:
"C:\DIR\Photo_Random-String"
and need a script that will check this whole name [Photo and Random String]  and write it as %FolderName%.

I didn't understand your question when you posted it - it seems what you wanted to do is delete a folder if it existed.

JFTR knowing the actual details of the path\folder can make a difference to the code, with spaces etc.

Last edited by foxidrive (13 Jul 2015 20:43)

Offline

Board footer

Powered by