DysfunktinaL Posted August 5, 2006 Share Posted August 5, 2006 So I need a batch file for some systems at work. Basicaly, we need it to look in a dir. and delete a couple directorys that are not at least a specific data size. Then after deleteing all the dirs, leaving the correct one, I need to locate and destroy a specific file within it. the problem is the dir. is never the same, but they all have the same format "Netfragz#".If anyone thinks they can help me with this project I'd appreciate it. Link to comment Share on other sites More sharing options...
jaclaz Posted August 5, 2006 Share Posted August 5, 2006 It shouldn't be a problem.Can you post a dir of an example directory tree?Just issue from command prompt DIR > C:\testdir.txtA basic idea:@echo off & setlocal ENABLEEXTENSIONS::DIRSIZE COMPARE::by Jacopo Lazzari::thanks to Rob van Der Woude for the examples, tutorials and ::info on his page http://www.robvanderwoude.com/::and to Simon Sheppard http://www.ss64.com/::-----------------------------------------------------------::Usage: Dirsize <PATH> [size to compare]::-----------------------------------------------------------for /f "tokens=*" %%a in ('dir/w/s/-c %1 ^|findstr "File"') do (set sizeline=%%a)echo Directory %1 - %sizeline%for /f "tokens=3 delims= " %%a in ("%sizeline%") do set dsize=%%aSET dsizeSET limit=%2SET /A Result = (%dsize% - %limit%)SET resultSET minus=%result:~0,1%SET minusIF "%minus%."=="-." (echo %dsize% is smaller than %limit%) ELSE (echo %dsize% is bigger than %limit%)jaclaz Link to comment Share on other sites More sharing options...
pmshah Posted August 11, 2006 Share Posted August 11, 2006 Download free "4dos 7.5"" from JP software. Go through their help file. What you want to achieve would be a child's play with it. Link to comment Share on other sites More sharing options...
DysfunktinaL Posted August 14, 2006 Author Share Posted August 14, 2006 Re: jaclazBasicaly, we use a special login system for Counter-Strike @ my work (Internet Cafe). The way it works, is it connects to a server that holds 30 Steam Logins, and that server manages available logins (NetFragz1-30). When a client logs into the server to request an ID, it checks for "C:/Program Files/Steam/SteamApps/NetFragz#". If that folder exists, it renames it to NetFragz# (where # = the number of the login it just recived). If that folder does not exist, it creates a new one in place of it, and then copys the dir to it on demand from the server. For some reason though, it won't catch the NetFragz# folder, and it simply makes a new one.The problem with this, is now the clients have to re-download everything from the back server on demand, and then all the custom items from the servers like sound files, maps, models, and crap like that. This wouldn't be too big of an issue, but to make an example. The correct folder size is ~4.7g. When I see incorrect folders in the client comps, they are ~50meg - ~300 meg. This puts a large load on our network, not to mention wasted harddrive space on the computers (all 50 + servers). On occasion, I find as many as 5 folders anywhere from 150megs-300megs. It also messes with out 3'rd party steam games. Those must be placed in a specific location within the dir, or else they will not launch correctly. I.E. for one of them, they must be in "C:/Program Files/Steam/SteamApps/NetFragz#/halflife/vs" but instead it is placed into "C:/Program Files/Steam/SteamApps/NetFragz#/vs".You can see the dillema. So the code would basicly need to do the following:Connect to remote computer (list of remote computers, or possibly added to the startup files on the local system), and scan "C:/Program Files/Steam/SteamApps/" for -folders- less then ~4g, and then delete them.Then it needs to locate the 1 folder that is bigger then ~4g, and rename it to NetFragz1.I'd also need to put in some other lines, but those I can do myself. Just typical search and destroy within the folder once it is named NetFragz1. The biggest thing though, is within that dir there are some files ranging from 100megs-2g, they are not folders, so it needs to leave those in tact.Any help would be appreciated. Link to comment Share on other sites More sharing options...
jaclaz Posted August 18, 2006 Share Posted August 18, 2006 (edited) If I have got it right, this should work:@echo off & setlocal ENABLEEXTENSIONS::STEAMDIR DELETE::by Jacopo Lazzari::thanks to Rob van Der Woude for the examples, tutorials and ::info on his page http://www.robvanderwoude.com/::and to Simon Sheppard http://www.ss64.com/::-----------------------------------------------------------::Usage: STEAMDIR::-----------------------------------------------------------::::Following five lines must be customized to actual paths:Set SERVER_AD=\\10.2.7.2\Set SERVER_SHARE=C_on_serverSet SERVER_PATH=\Program Files\Steam\SteamAppsSet SERVER_DIR=\NetFragzSet Limit=4500000000::Above five lines must be customized to actual pathsSet BASE_PATH=%SERVER_AD%%SERVER_SHARE%%SERVER_PATH%DIR "%BASE_PATH%">NUL 2>NULIF %ERRORLEVEL% NEQ 0 (ECHO Folder %BASE_PATH% does not exist!Echo Exiting batch...GOTO :EOF)Set BASE_PATH=%SERVER_AD%%SERVER_SHARE%%SERVER_PATH%%SERVER_DIR%Set Number=1:LOOPSet FULL_PATH="%BASE_PATH%%Number%"ECHO Checking folder %SERVER_DIR%%Number% ....DIR %FULL_PATH%>NUL 2>NULIF %ERRORLEVEL% NEQ 0 ECHO Folder does not exist... &GOTO :Skipfor /f "tokens=*" %%a in ('dir/w/s/-c %FULL_PATH% ^|findstr "File"') do (set sizeline=%%aif not defined sizeline set sizeline=%Limit%)echo Directory %SERVER_DIR%%Number% - %sizeline%for /f "tokens=3 delims= " %%a in ("%sizeline%") do set dsize=%%aSET /A Result = (%dsize% - %Limit%)SET minus=%result:~0,1%IF "%minus%"=="-" (echo %dsize% is smaller than %Limit%echo Are you sure you want to delete it?echo Press Ctrl+C to abortPAUSERMDIR /S /Q %FULL_PATH%)IF %number%==1 goto :SkipDIR "%BASE_PATH%1">NUL 2>NULIF %ERRORLEVEL%==0 (Echo.Echo Folder %SERVER_DIR%%Number% is bigger than limitEcho but a folder named %SERVER_DIR%1 already exists! Echo Skipping...GOTO :Skip)MOVE %FULL_PATH% "%BASE_PATH%1":SkipSet /A Number=%number%+1If not %Number%==31 goto :loopYou must set your exact paths and size limit (in bytes).As it is, it skips ANY folder bigger than size limit, after the first one has been found and (if not already #1) copied to folder#1.Please adapt it to your exact needs and report (hopefully) success.jaclazP.S.: Double check line breaks inserted by board software, this:for /f "tokens=*" %%a in ('dir/w/s/-c %FULL_PATH% ^|findstr "File"') do (must be on the same line Edited August 18, 2006 by jaclaz Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now