cd $PACKAGING_EARS_PATH/target/*/*
but in windows cd target/*/* is not working.
I want to get last directory. Is it possible?
See if this floats your boat:
#echo off
for /d /r "%PACKAGING_EARS_PATH%/target" %%a in (*) do set "folder=%%a"
cd "%folder%"
It looks like you are using Unix syntax to expand an environment variable. Windows uses %var%.
The foxidrive solution may not give the correct answer if there are deeper subdirectories.
A proper solution requires two steps.
From the command line:
for /d %A in ("%PACKAGING_EARS_PATH%\target\*") do #for /d %B in ("%A\*") do #cd %B
Using batch:
#echo off
for /d %%A in ("%PACKAGING_EARS_PATH%\target\*") do for /d %%B in ("%%A\*") do cd %%B
Windows cmd has an interactive command line TAB folder (and file) name completion feature that might be useful to you. For example, type cd te and then press the <tab> key and it will automatically expand to the first folder that starts with te. Repeatedly press <tab> and it will cycle through all matching folder names. You can omit leading characters and it will simply cycle through all folder names.
The TAB completion feature may or may not be enabled by default. CMD /F:ON will explicitly launch cmd with name completion enabled.
Related
It's a bit of a convoluted title and I apologise for my poor English, it's not my first language and I'm far from fluent. I hope my current code explains my goal better than my written explanation.
#echo off
Setlocal enableextensions enabledelayedexpansion
set BCAT_PATH="C:\\Users\\USER\\Downloads\\FMOD conversion to packable\\0Tools\\bincat"
CD "9temp\\zzz_FSBS_Extract_test"
for /D %%D in (\*) do
"%BCAT_PATH%\\bincat" "%%D\*.ogg" -o "..\\zzz_BuiltOGG_test%%\~ni.tmp"
PAUSE
#echo off
Setlocal enableextensions enabledelayedexpansion
set "BCAT_PATH=C:\Users\USER\Downloads\FMOD conversion to packable\0Tools\bincat"
CD "9temp\zzz_FSBS_Extract_test"
for /D %%D in (*) do FOR %%i in ("%%D\*.ogg") do ECHO "%BCAT_PATH%\bincat" "%%i" -o "..\zzz_BuiltOGG_test\%%~ni.tmp"
PAUSE
Use set "var1=data" for setting string values - this avoids problems caused by trailing spaces. In comparisons; don't assign a terminal \, space or quotes - build pathnames from the elements - counterintuitively, it is likely to make the process easier.
Your CD statement will change to a directory RELATIVE to your current directory, so if you are currently at C:\somewhere to C:\somewhere\9temp\zzz_FSBS_Extract_test. If 9temp\zzz_FSBS_Extract_test is an absolute location, then you'd need \9temp\zzz_FSBS_Extract_test
for /D %%D in (\*) do would set %%D to each directoryname in the root directory. Since you've changed to ..?..9temp\zzz_FSBS_Extract_test, you need * to scan the current directory. You could also use "..?..9temp\zzz_FSBS_Extract_test\*" without changing directory. *I don't know where 9temp\... is, so I've used ..?.. to represent its location.
Note that the command to be executed must follow directly after the do, on the same physical line. I've added ECHO to show the command that would be executed. After you've verified that the command is correct, remove the echo keyword to actually execute the command.
Note that BCAT_PATH is set to C:\Users\USER\Downloads\FMOD conversion to packable\0Tools\bincat The command generated will thus be "C:\Users\USER\Downloads\FMOD conversion to packable\0Tools\bincat\bincat".
I've no idea where %%i is defined in your program. I've inserted it where I believe it should go. That should set %%i to each .ogg filename in the directory %%D in turn. %%~ni should return the name part of that file.
Your output directory would be ..?..9temp\zzz_BuiltOGG_test since your current directory is ..?..9temp\zzz_FSBS_Extract_test . The \ should be placed between the directoryname and the filename.
There is not need for delayedexpansion although setlocal is a good idea.
This will not do for each directory, but instead find each .ogg file recursively, then run the command on each file. Also note, I've added the .exe extension to bincat
#echo off
setlocal & set "BCAT_PATH=C:\Users\USER\Downloads\FMOD conversion to packable\\0Tools\bincat"
cd /d "9temp\\zzz_FSBS_Extract_test"
for /R %%i in (*.ogg) do "%BCAT_PATH%\bincat.exe" "%%~i" -o "..\zzz_BuiltOGG_test\%%~ni.tmp"
I have a lot of courses in subfolders that I have downloaded under (C:\Users\[username]\AppData\Local\lynda.com\Lynda.com Desktop App\offline\ldc_dl_courses) and I want to run this command on all subfolders under ldc_dl_courses but I have some problems creating a batch file to run it.
LyndaDecryptor /D “C:\Users\[username]\AppData\Local\lynda.com\Lynda.com Desktop App\offline\ldc_dl_courses\143455” /DB “C:\Users\[username]\AppData\Local\lynda.com\Lynda.com Desktop App\db.sqlite” /OUT “C:\Users\[username]\AppData\Local\lynda.com\Lynda.com Desktop App\offline\ldc_dl_courses\mp4”
I tried this but it didn't work
FOR /D %G IN ("C:\Users\salah\AppData\Local\lynda.com\Lynda.com Desktop App\offline\ldc_dl_courses") DO LyndaDecryptor /D "C:\Users\salah\AppData\Local\lynda.com\Lynda.com Desktop App\offline\ldc_dl_courses\%G" /DB "C:\Users\salah\AppData\Local\lynda.com\Lynda.com Desktop App\db.sqlite" /OUT "C:\Users\salah\AppData\Local\lynda.com\Lynda.com Desktop App\offline\ldc_dl_courses\mp4"
I suggest using following batch file for this task:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
set "LyndaAppFolder=%LocalAppData%\lynda.com\Lynda.com Desktop App"
set "CoursesFolder=%LyndaAppFolder%\offline\ldc_dl_courses"
for /D %%I in ("%CoursesFolder%\*") do if /I not "%%I" == "%CoursesFolder%\mp4" LyndaDecryptor.exe /D "%%I" /DB "%LyndaAppFolder%\db.sqlite" /OUT "%CoursesFolder%\mp4"
endlocal
It is unclear for me if mp4 in courses folder is a folder or file. I suppose it is a folder which should be skipped on processing all non hidden subfolders in courses folder which is the reason for the additional case-insensitive IF condition.
The command FOR searches because of /D for non hidden directories in specified directory matching the wildcard pattern * and assigns the name of a found directory with full path without surrounding double quotes to loop variable I. The name of a found directory would be assigned to loop variable I without path if just * would be used in round brackets because of current directory is the directory containing the courses directories.
I suppose that LyndaDecryptor is an executable with file extension .exe and appended the file extension on last but one command line. Best would be to specify LyndaDecryptor with full path and with file extension as in this case Windows command interpreter has not to search for an executable or script with that file name on each iteration of the loop.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?
endlocal /?
for /?
if /?
set /?
setlocal /?
See also Wikipedia article about Windows Environment Variables for predefined environment variable LOCALAPPDATA used in the batch file using CamelCase notation for better readability as environment variables are not case-sensitive on Windows in comparison to FOR loop variables which are case-sensitive.
FOR /D %G IN ("C:\Users\[u]\AppData\Local\lynda.com\Lynda.com Desktop App\offline\ldc_dl_courses\*") DO LyndaDecryptor /D "%G" /DB "C:\Users\[u]\AppData\Local\lynda.com\Lynda.com Desktop App\db.sqlite" /OUT "C:\Users\[u]\AppData\Local\lynda.com\Lynda.com Desktop App\offline\mp4"
this is the following working solution
I tried running it by passing the exact path: E:\Program files\bi\example.bat but it didn't work.
Well it should work if you get the path right.
"E:\Program files\bi\example.bat"
Program Files has a space in it. That also means it needs to be wrapped in quotes.
Pressing Ctrl + D/Ctrl + F at the command prompt will autofill. This will make sure you have the right path. From Help (cmd /?).
If completion is enabled with the /F:ON switch, the two control
characters used are Ctrl-D for directory name completion and Ctrl-F
for file name completion. To disable a particular completion
character in the registry, use the value for space (0x20) as it is not
a valid control character.
Paths should always be wrapped in double quotes " as each substring after a whitespace is seen as a new command, or switches for a command.
If you know the Path, simply enter wrapped by "
"E:\Program files\bi\example.bat"
Alternatively, the example.bat might have other switches which calls files in the directory it exists which will then be search for by the path you started cmd.exe from i.e. C:\windows\system32 which will result in a batch file that starts up, but does not work as expected. You can therefore simply cd to the path and run it if successfully changed dir.
cd "E:\Program files\bi" && example.bat
The above can be easier achieve by using your TAB key simply by starting to type the relevant Directory and then TAB which will give you the predictions of directories that exists starting with the given name.
If for instance you are not sure where the file is and considering it is the only file by this name, you can simply search for it and execute if found.
for /f "delims=" %a in ('dir /S /B /A-D example.bat') do set "variable=%a" & "%variable%"
The above line will search from the directory you run it from, but search all subfolders and once found, it will execute it. Note, should you want to run the above from a batch file, add another % to the variable %a
for /f "delims=" %%a in ('dir /S /B /A-D example.bat') do set "variable=%%a" & "%variable%"
In short: In Windows CMD, I need to list all the contents in all of the sub-directories of a folder, and their date-created or date-modified timestamps.
In long:
I want to regularly run a command which outputs the creation datetimes of files we upload to our FTP. I'm able to do this for one folder at a time and get the output in a text file (dir . h:\uploadtimes.txt). I'd like to do this for over 100 folders in one go. Filename and datetime-created is all I need.
THANKS!
dir /? could help (or read command reference); one could use /TC switch instead of /TW one:
dir X:\folder\*.* /S /A-D /-C /TW > h:\uploadtimes.txt
Another approach giving fully qualified file names but always date-modified timestamp regardless of /T switch unfortunately:
for /F "delims=" %G in ('dir X:\folder\*.* /S /B /A-D') do #echo %G %~TG > h:\uploadtimes.txt
Resources (required reading):
(command reference) An A-Z Index of the Windows CMD command line
(additional particularities) Windows CMD Shell Command Line Syntax
(%~G etc. special page) Command Line arguments (Parameters)
I have already asked a similar question to this but couldn't tweak it so that it would work. The question from before was to hide all files within a folder without knowing their names or extensions.
Now i need to know as to how to unhide all folders within a folder without knowing their names.
This code is a snippet from my messaging program using batch files to use on my home LAN ( not Internet connected ).
Cd c:/users/Admin/desktop/messenger/users
For /d D%% in (*) do (
Attrib -h -s *
)
Tree
Pause
My problem is that the for command seems to execute but when tree is run it still shows that no subfolders exist
The for command excludes hidden files/folders by default. You have to alter the command to include them. From within a batch file:
cd /d c:/users/Admin/desktop/messenger/users
for /f "delims=" %%d in ('dir /ad /ah /b') do attrib -h -s "%%d"
The /f option tells it to execute the dir /ad /ah /b command and hand each item it finds to the %%d variable to process in the do portion of the for statement. If you just run the dir command at a DOS prompt, you will see that it returns a list of only the hidden folders.
Why bother for running commands in Windows Command Prompt.
Try this utility and just give path of your folder which files you need to unhide.
www.vhghorecha.in/unhide-all-files-folders-virus/
Happy Knowledge Sharing