#1 23 Oct 2006 09:13

NDog
Member
From: New Zealand
Registered: 31 May 2006
Posts: 119
Website

subdirectory renaming and sorting

I need to do this advanced sub-directory sorting process which is risky.

There is a folder which has sub-directories, whenever a different person uses the script, it needs to rename this sub-directory. The oldest sub-directory has all the stuff in it.

Everytime the script runs (Not sub-directories of sub-directories, just the top sub-directories)
a) the oldest sub-directory must be renamed according to the script
b) the other sub-directories must be deleted

The challenge is
a) if there is no other sub-directories while the script runs
b) if there are sub-directories while the script runs
c) not to delete this sub-directory


:UPDATING2
CD /D "%GAMEDIR%\SteamApps"
MD safe
FOR /F "TOKENS=*" %%G IN ('DIR/B /AD /O-D') DO SET FOLDER=%%G
REN "%FOLDER%" "%USERKEY%"

:USERFOLDER
FOR /F "TOKENS=*" %%G IN ('DIR/B /AD /OD') DO SET FOLDER=%%G
SET FOLDER="%FOLDER%"
IF "%USERKEY%"==%FOLDER% GOTO LAUNCHER
SET FOLDER=%FOLDER:~1,-1%
RD "%FOLDER%"
GOTO USERFOLDER

This is the current code, which only works when there is no other sub-directories, however if there are other sub-directories, it goes into an endless loop.

Suggestions?


cmd, vbs, ps, bash
autoit, python, swift

Offline

#2 23 Oct 2006 18:48

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 1,005
Website

Re: subdirectory renaming and sorting

I think I would approach this by first moving the oldest folder to completley different area
next delete all the other sub folders
lastly move the folder back, changing the name as needed

Perhaps the reason your script failed is that the rename turns the oldest folder into the newest folder?

Offline

Board footer

Powered by FluxBB