String Manipulation on environment variables
Moderator: DosItHelp
String Manipulation on environment variables
Hi to all.
I want to extract a string from
C:\Documents and Settings\Administrator\Application Data
I need only the Application Data
environment variable %APPDATA% = C:\Documents and Settings\Administrator\Application Data
so I want to extract from it, since it is not the same on different windows language versions.
Example: Application data on German windows is C:\Dokumente und Einstellungen\All Users\Anwendungsdaten
so here I will need Anwendungsdaten
So basically I need the string from the end to the backslash "\"
I didn't find a way in DOS to search for string from EOF backwards to \ and then to delete the rest or to save from \ to EOF in a new variable.
If someone could help, I would be very grateful.
Milos
I want to extract a string from
C:\Documents and Settings\Administrator\Application Data
I need only the Application Data
environment variable %APPDATA% = C:\Documents and Settings\Administrator\Application Data
so I want to extract from it, since it is not the same on different windows language versions.
Example: Application data on German windows is C:\Dokumente und Einstellungen\All Users\Anwendungsdaten
so here I will need Anwendungsdaten
So basically I need the string from the end to the backslash "\"
I didn't find a way in DOS to search for string from EOF backwards to \ and then to delete the rest or to save from \ to EOF in a new variable.
If someone could help, I would be very grateful.
Milos
Re: String Manipulation on environment variables
thank you, I just typed this in cmd and I have an error:
%%a was unexpected at this time
Re: String Manipulation on environment variables
Of course. This was made for a batch file.
For the command prompt use
Regards
aGerman
For the command prompt use
Code: Select all
for /f "delims=" %a in ("%appdata%") do @echo %~nxa
Regards
aGerman
Re: String Manipulation on environment variables
aGerman wrote:Of course. This was made for a batch file.
For the command prompt useCode: Select all
for /f "delims=" %a in ("%appdata%") do @echo %~nxa
Regards
aGerman
Thank you very very much !!!
Can you please make me a batch command for this.
I will assign a new variable to your command -let's call it %NEW%
Copy the file my.txt to C:\Documents and Settings\All Users\Application Data\
Meaning
%NEW% = for /f "delims=" %%a in ("%appdata%") do echo %%~nxa
copy "my.txt" %ALLUSERSPROFILE% \ %NEW%
Re: String Manipulation on environment variables
Here you are
But note: There isn't such a path in Win7!
I suggest you should read the registry key instead
It's slower and more code, but it's much safer.
Regards
aGerman
Code: Select all
for /f "delims=" %%a in ("%appdata%") do set "NEW=%%~nxa"
copy "my.txt" "%ALLUSERSPROFILE%\%NEW%\"
But note: There isn't such a path in Win7!
I suggest you should read the registry key instead
Code: Select all
for /f "tokens=2*" %%a in (
'reg query "HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage" /v "ACP" ^| find /i "ACP"'
) do chcp %%b >nul
for /f "tokens=3*" %%a in (
'reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Common AppData" ^| find /i "Common AppData"'
) do set "CommonAppData=%%b"
for /f "tokens=2*" %%a in (
'reg query "HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage" /v "OEMCP" ^| find /i "OEMCP"'
) do chcp %%b >nul
copy "my.txt" "%CommonAppData%\"
It's slower and more code, but it's much safer.
Regards
aGerman
Re: String Manipulation on environment variables
Thank you very much!
In Win7 and in Vista yes, but the problem is Win XP, that is why I must to this.
In Win7 and in Vista yes, but the problem is Win XP, that is why I must to this.
Re: String Manipulation on environment variables
I see. But reading the registry value will work for XP, Vista and Win7. Thats why I would prefer this.
Regards
aGerman
Regards
aGerman