Solved Script wriring help (Attn: Pyprohly)

PepFontana

New member
Local time
4:13 PM
Messages
3
Hello,

I found the below script on this very website (http://www.sevenforums.com/general-...osing-custom-icons-removable-flash-drive.html) written by user Pyprohly. I am in the exact same situation as the person that originally posted, however there is one small piece of it that I am having trouble with.


I have a portable hard drive with a bunch of video files on it. When I create custom folder icons for each video, they are fine until I take the hard drive to a different PC and plug it in. Thru the above mentioned thread, I was able to determine that the problem was with the desktop.ini file listing the drive letter in the path to the icon file. If you edit the desktop.ini file and remove (In my case) the I: part of the path, it no longer matters what drive letter the various PC's assign and the icon files work as I want them to.

The problem I am having is that when I use the script in the above thread the script works perfectly if you have the files_named_like_this. If you have the file named without the underscores say for example "Jims Hockey Game" the script appears to be only using the last word in the title when it tries to write the file back into the folder. The script fails saying that the path was not found (in this example it would show that it was looking for the “I:\Game” path). This error happens to every folder that has a title with spaces in it. If the folder happens to only have a single word in the title, the script works fine and renames the .ini file.

Would someone happen to know how to edit this script to have it work correctly with files that have spaces between the words in the folder title?


I have attached a picture of what the error looks like when I run the script and I also have attached the script that is in the above link.


Thank you for any help that can be provided.
 

Attachments

My Computer

Computer type
PC/Desktop
OS
Windows 7 Pro 64bit
Try sending Pyprohly a PM (Private Message).

Edit: I see you are a new user so you will not be able to send a PM yet. I sent one for you.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Lenovo IdeaCenter 450
OS
Windows 10 Pro X64
CPU
Intel Quad Core i7-4770 @ 3.4Ghz
Memory
16.0GB PC3-12800 DDR3 SDRAM 1600 MHz
Graphics Card(s)
Intel Integrated HD Graphics
Sound Card
Realtek HD Audio
Monitor(s) Displays
HP 22" LCD
Screen Resolution
1680 x 1050
Hard Drives
250GB Samsung EVO SATA-3 SSD
2TB Seagate ST2000DM001 SATA-2
1.5TB Seagate ST3150041AS SATA
Keyboard
Dell USB
Mouse
Lenovo USB
Internet Speed
Cable via Road Runner 3MB Upload, 30MB Download
Antivirus
Windows Defender, MBAM Pro, MBAE
Browser
Seamonkey
Other Info
UEFI/GPT
PLDS DVD-RW DH16AERSH
LOL, thanks. I searched for 15 minutes last night looking for the PM feature. I thought I was going crazy.

Thank you for forwarding that for me.
 

My Computer

Computer type
PC/Desktop
OS
Windows 7 Pro 64bit
Hey, sorry for any delay,

Thank you, PepFontana, for raising the error to my attention. That thread you mention, I think, was probably the third or so thread I ever assisted to here at Seven Forums. So I wouldn't be surprised if that batch script is riddled with other kinds of issues.


I rewrote a new batch script, from ground up, which may help you with your issue, PepFontana.



Find_And_Replace_Text.bat
Code:
@echo off
setlocal EnableDelayedExpansion

::
set find="F:"
set replace=""
set case_sensitive=TRUE
set line_must_start_with="IconResource",
::
set filemasks="desktop.ini",
set recurse=TRUE
set write_attributes=TRUE
::

pushd "%~dp0"& echo.
set tempfile="%TEMP%\tmp%RANDOM%_%~nx0.txt"
if /i %RECURSE%==TRUE set recurse_=/s
if /i %CASE_SENSITIVE%==TRUE ( set case_sensitive_=) else ( set case_sensitive_=/i)
if /i %WRITE_ATTRIBUTES%==TRUE ( set write_attributes_=) else ( set write_attributes_=REM )
for /f "delims=" %%I in (' dir /a:-d /b %RECURSE_% %FILEMASKS% ') do (
	set/p=Processing "%%~fI"... <NUL
	%WRITE_ATTRIBUTES_% attrib "%%~fI" -r -s -h
	copy NUL "%TEMPFILE:"=%" /y >NUL
	for /f "tokens=1,* delims=]" %%L in (' find /n /v "" ^< "%%~fI" ') do (
		if not "%%~M"=="" for %%P in ( %LINE_MUST_START_WITH% ) do (
			set line=%%M& echo.%%M| findstr /i "^%%~P" >NUL && (
				if /i %CASE_SENSITIVE%==TRUE (
					echo.%%M| findstr "%FIND:"=%" >NUL && (
						set line=!LINE:%FIND:"=%=%REPLACE:"=%!
					)
				) else ( set line=!LINE:%FIND:"=%=%REPLACE:"=%!)
			)
		) else ( set line=)
		echo.!LINE!>>"%TEMPFILE:"=%"
	)
	copy "%TEMPFILE:"=%" "%%~fI" /y >NUL
	%WRITE_ATTRIBUTES_% attrib "%%~fI" +s +h
	del "%TEMPFILE:"=%" /f /q
	echo Done.
)
echo.& echo Complete.
popd
 

Attachments

Last edited:

My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
Outstanding!! It works perfectly. :D:D:D

Thank you so, so much.
 

My Computer

Computer type
PC/Desktop
OS
Windows 7 Pro 64bit
Back
Top