Computer Hope
Microsoft => Microsoft DOS => Topic started by: mioo_sara on March 01, 2014, 07:15:11 AM
-
hi to all
i want to rename my current folder (folder that i am in it) is it possible?
with this script i can find my folder name but i cant rename it
for %%* in (.) do @echo %%~n*
pause
ren "%%~n*" "new"
whats wrong?
if its possible i want to remove any www.*.com from current folder name and replace it with space
1- find current folder's name
2-if there is any www. ???* .com in its name rename it(replace www. ???* .com )with space
-
I don't think it can be done if the folder is in use,....
-
patio is right.
You have to cd out of the folder, rename it and cd back in. This assumes that no tasks are open in the folder or tree, too.
-
patio is right.
You have to cd out of the folder, rename it and cd back in. This assumes that no tasks are open in the folder or tree, too.
ok guess we stepped back one level now how could it be done?
i want program to do this
1- find current folder's name
2- if there is www.??*.com in current folder's name
so step one level back and
3- rename it(remove www.??*.com and replace it with space)
4- create a text file named password and write www.??*.com in it
how should i do it?
-
Show us some examples of the actual folder name.
The easiest method to use depends on the format of the folder name.
-
C:\Users\Me\testme>for /f "delims=" %N in ("%cd%") do cd.. & ren "%~dpnN" "newname" && cd "newname"
C:\Users\Me\testme>cd.. & ren "C:\Users\Mike\testme" "newname" && cd "newname"
C:\Users\Me\newname>
-
Show us some examples of the actual folder name.
The easiest method to use depends on the format of the folder name.
dear foxidrive
i have lots of folders most of them containing files (compressed password protested)
folders have website's names on themselves
example
win_media.player.12(www.dowloadfree.com)include.patch
format.factory(www.getfree.net)freeware
1-i want websites name( in folder names) removed and replaced with empty space
2- put website name in a file(password.text) and save it in that folder
3- if i am in the current folder with website's name you know what to do
i think we should step back one level and do above instructions
these scripts will be used in a third party program later
thanks
-
dear Salmon Trout
it didn't worked just created a for and cd file in my current folder
please read my last 2 post above
thanks
-
4- create a text file named password and write www.??*.com in it
This sounds interesting. What is it for?
-
passwords.text will be a file that later will be used by a third party program
theses batches too :)
now please write for 8) me a batch
-
Heeee...this should be good.
-
He lost me from the start.
Windows assigns folders for each user.
To rename the folder that has the user's name is a security and logical problem.
{begin sarcasm}
Imagine three user on a computer, Alice, Bib can Carl.
Alice wants to change her name to Carl, but still have her folder named Alice.
So Carl must change his name, put still have his folder.
Unable to resolve this they ask Bob.
Bob does not want to help!
What is the scrip that can handle that?
{end sarcasm}
-
win_media.player.12(www.dowloadfree.com)include.patch
format.factory(www.getfree.net)freeware
.... and you thought we wouldn't check those sites out?
1-i want websites name( in folder names) removed and replaced with empty space
I expect you do.
2- put website name in a file(password.text) and save it in that folder
*censored*, we're just a bunch of stupid coders who don't care... we'll help you with passwords, freeware, (passworded freeware????) odd looking sites? Great!
i think we should step back one level
Well, I'm stepping back several levels.
these scripts will be used in a third party program later
I have no doubt they will.
-
compressed password protested
methinks the password doth protest too much.
-
win_media.player.12(www.dowloadfree.com)include.patch
format.factory(www.getfree.net)freeware
1-i want websites name( in folder names) removed and replaced with empty space
How many spaces do you want left between the ( )?
There could be issues with making a robust solution because the name format can be variable. You could have names like this:
win_media.player(type 2).12(www.dowloadfree.com)include.patch
format.factory(www.getfree.net)freeware(supports Win2K)
and the only way for a script to know which set of parentheses to work with is that in these two examples there is a www. after the opening (
but it is possible that the website will not have a www. at the beginning of the URL.
-
thanks dear foxidrive
i think you're the only one that cares about question itself but others are all gouging :P
well folders are with passwords in their names and i want just 1- store those passwords in a file (password.text) in their folder and then remove password (and replace with 1 space)
so final folder's name should be something like example below
example
best answers(www.my-website.com)all members
should rename to
best answers all members
==========================
my_broadcasting_www.mediafree.net
should rename to
my_broadcasting
-
best answers(www.my-website.com)all members
should rename to
best answers all members
==========================
my_broadcasting_www.mediafree.net
should rename to
my_broadcasting
This makes the job more difficult as there is no well defined format for the password.
-
This makes the job more difficult as there is no well defined format for the password.
i know at this particular time i don't need passwords i just want to remove them from folder's name
i tried script below it's working and removed www.*.com from folder's name but i should type www.*.com for every folder
i want program detect it automatically
for /f "tokens=* delims= " %%i in ('dir /b "*.*"') do Set LIST=%%i& set LIST | ren "%%~fi" "%%LIST:www.my-website.com= %%"
by the way i tested it on a file and not a folder
but this one works on folders very good but i want www.?.com or www.?.net detect automatically and replaced with space
EECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /D /R %%i IN (*.*) DO (
SET "n=%%~nxi"
SET n=!n:www.myp30.com= !
::SET n=!n:www.myp30.net= !
IF NOT "!n!" == "%%~nxi" MOVE "%%~i" "%%~dpi!n!"
)
-
The task does not have a well defined format so a general script is impossible and so it has to have an exception for every type of format that is used.
This batch file works for the two formats you have shown, and will handle www.*.com and www.*.net, and it uses the repl.bat tool by Dave Benham.
It creates the password.txt file inside the folder with the website address
- and the batch file has to be launched from the path and not located inside the folder, because doing that would lock the folder itself and the rename would fail.
If you can deal with this folder "best answers(www.my-website.com)all members"
becoming this "best answers()all members"
and this folder "my_broadcasting_www.mediafree.net"
becoming this "my_broadcasting_"
so that only the website address is removed then it could be simplified and would handle other folder-name formats.
V2.0
@echo off
for %%a in ("%cd%") do set "folder=%%~nxa"
cd..
del renfolder.bat 2>nul
:: handles (www.aaa.com)
echo "%folder%"|repl ".(.*)\((www\..*?\.com)\)(.*)." ">$&\password.txt echo $2& ren $& \q$1 $3\q" axi >>renfolder.bat
:: handles (www.aaa.net)
echo "%folder%"|repl ".(.*)\((www\..*?\.net)\)(.*)." ">$&\password.txt echo $2&ren $& \q$1 $3\q" axi >>renfolder.bat
:: handles _www.aaa.com
echo "%folder%"|repl ".(.*)_(www\..*?\.com)(.*)." ">$&\password.txt echo $2&ren $& \q$1 $3\q" axi >>renfolder.bat
:: handles _www.aaa.net
echo "%folder%"|repl ".(.*)_(www\..*?\.net)(.*)." ">$&\password.txt echo $2&ren $& \q$1 $3\q" axi >>renfolder.bat
call renfolder.bat
del renfolder.bat 2>nul
pause
This uses a helper batch file called `repl.bat` - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat
Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.
-
well dear foxidrive i tested your script but i wonder if it was my problem :P or the script but it didn't worked!
here's what i did for testing the script
1-i made a new folder named it test folder
2- inside it i made another 2 folders with website name in their names
examle
my-testing1_www.myweb.com_in test
my-testing2_www.mysite.net
3- now i copied both (repl.bat and test-batch.bat) in test folder (next to those folders)
now i tried the script test-batch.bat but nothing happened
what do you think? ???
-
3- now i copied both (repl.bat and test-batch.bat) in test folder (next to those folders)
now i tried the script test-batch.bat but nothing happened
Perhaps I wasn't clear enough but I said this:
- and the batch file has to be launched from the path and not located inside the folder, because doing that would lock the folder itself and the rename would fail.
You must put the batch file and repl.bat in a folder on the path, such as c:\windows or c:\windows\system32
When you are at a cmd prompt inside the folder, then you type the batch-command
-
dear foxidrive
i tested your v2 script and i don't know why it's still not responding correctly ???
here's result of my test
=====================================================
1-first of all i have windows xp sp3 installed on my pc and my win-xp is in drive f:
(i don't think if it would be the reason of that)
2- in first try i copied both files(repl.bat and test-batch.bat) to f:\windows
then i clicked on f:\mytest\go.bat
(inside of go.bat there is this comment f:\windows\test-batch.bat )
nothing but a black screen that has vanished!
inside folder ( f:\mytest\ ) there are some folders that their names have website's name
i checked them but nothing has been changed! no rename and no password.txt
3- so in another test i copied both (repl.bat and test-batch.bat) to f:\windows\system32
but still nothing happened
4- in another test i tried CMD i opened CMD and typed f:\mytest\go.bat
still no successful result ::)
=============================
now i have some questions
should i really do this process with copying some files in windows?
i mean to me it doesn't seem to be that difficult for a task like this
i think program can do some Dir find folders that their names has letters begin with (www.) and end with .com or .net and remove these letters from begin to end right?
and create a password.text in folder containing (www.....com)
-
You said that you wanted to do this from inside the folder. You can't click on a batch file inside the folder though because it will lock the folder and it cannot be renamed.
Just to prove it works, place the two batch files repl.bat and test-batch.bat into c:\windows and then open a cmd prompt inside the folder to be renamed.
Then type test-batch and you should see the folder renamed and a password.txt appear inside the folder.
-
wow ! dear foxidrive
it actually worked !! i can't even believe it ! ;D ;D ;D :D :D :D :D
you know if you read my first post in this topic i was looking for a way to rename my current folder but cuz it was being used by the explorer and even batch itself some guys in the forum said it's not possible . and i was disappointed so i changed my idea and tried another way(i decided to rename another folders and not current folder)
but now you proved that it's possible
thank you very very very much ;) ;) ;) ;) you solved one of my biggest problems cuz there where hundreds of folders that i wanted to be renamed but cuz my program was added to my right click menu i wanted just selected folder renamed and not all of them(that's my current folder story)
and sorry for the late answer i was out of town for a few hours
thanks again i hope you have very good year ahead for yourself and for your family
-
sorry to disturb you again dear foxidrive i don't know why program is not stable i mean i tried it with lots of other folders and although their structures where not different in names but program didn't worked anymore and i even tried to make a folder with my first test structure (first successful test) but it failed again and nothing happened
i even disabled my kaspersky antivirus but nothing changed
don't you think if it would be better to do it with DIR and if program found folder with website names ask if i want it to be renamed (yes/no)
i think copying .bat file in windows make it more unstable than before i can remove program from my right click menu (forget about current folder)and work with search and replace (yes/no)
what do you think?
-
;D ;D ;D ;D
now i'v found reason of the problem
problem was because of folder's name and( ) those that their names was in () just has been renamed
ok ! ok i can solve this problem dear foxidrive thanks again
:) :) :) :) :) :) :) :)