logo
Tags down

shadow

Make a folder name %prevMonth%"-"%prevYear=%"-01" using batch (.bat) files


By : user7447772
Date : October 16 2020, 03:08 PM
I wish did fix the issue. I want to create a folder naming it to the previous month. But my code does not seem to work. Here is my code. , Here'e an alternative using PowerShell:
code :
@Echo Off
For /F UseBackQ %%A In (
    `PowerShell "(Get-Date).AddMonths(-1).ToString('yyy-MM')"`
) Do If Not Exist "%%A-01\" MD "%%A-01"


Share : facebook icon twitter icon

Windows Batch: Search all files in file, if line contains "apple" or "tomato" echo it


By : jlavanya
Date : March 29 2020, 07:55 AM
I hope this helps . Findstr already does this for you :
code :
@findstr /i "tomato apple" *.txt
@echo off

for /f %%i in ('findstr /i "tomato apple" *.txt') do @echo I just found a %%i

It is possible to make a "Gif Viewer" with "Google Chrome" using batch? How to do "File Searche


By : Daniel
Date : March 29 2020, 07:55 AM
With these it helps I wrote a file chooser that you can use. Or you can just look at various parts, like how I launch chrome to show a file. Or how I search for all images in subdirectories, or whatever. I wanted to show how to do it without forcing the user to rename their .gif files.
You need to configure these variables at the top of the script:
code :
REM The location of the viewer to launch.
set VIEWER=C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

REM The root directory to look for files.  %~dp0 means the same directory as
REM this script, including a trailing \.
set FILES=%~dp0

REM The type of files to show.
set FILE_FILTER=^*.gif ^*.jpg ^*.png

REM When '/s', then include subdirectories below %FILES% in the search.  Leave
REM blank to restrict the search to %FILES% only.
set RECURSE=/s
  images\buffalo.gif
  images\bull7.gif
> images\cow13.gif
  images\cow14.gif
  more images\dino 10.gif
  more images\dino19.gif
Up[W]  Down[S]  Select[E]  Quit[Q]
@echo off

REM The location of the viewer to launch.
set VIEWER=C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

REM The root directory to look for files.  %~dp0 means the same directory as
REM this script, including a trailing \.
set FILES=%~dp0

REM The type of files to show.
set FILE_FILTER=^*.gif ^*.jpg ^*.png

REM When '/s', then include subdirectories below %FILES% in the search.  Leave
REM blank to restrict the search to %FILES% only.
set RECURSE=/s

REM ----------------------------
setlocal EnableDelayedExpansion

cls
call :show_splash_screen
call :pause_sec 2

set SELECTED_INDEX=0
set SELECTED=

:show_files
if %SELECTED_INDEX% LSS 0 ( set SELECTED_INDEX=0)

cls
call :ui_show_files "%FILES%" "%FILE_FILTER%" "%SELECTED_INDEX%"

choice /c QWSE /n /m " Up[W]  Down[S]  Select[E]  Quit[Q]"
if ERRORLEVEL 4 (
        REM User selected an option, so launch the viewer with the selected file
 as
        REM an argument.
        call "%VIEWER%" "%SELECTED%"
        goto :show_files
)
if ERRORLEVEL 3 ( set /a SELECTED_INDEX=!SELECTED_INDEX!+1 && goto :show_files )

if ERRORLEVEL 2 ( set /a SELECTED_INDEX=!SELECTED_INDEX!-1 && goto :show_files )

goto :eof

REM ui_show_files
REM Displays all the files in the directory given by %1, filtered by %2.  %3
REM indicates which file the user has selected.
REM
REM Returns %SELECTED%, which contains the filename of the selected file.
:ui_show_files
set COUNT=0
pushd "%~1"
for /f "tokens=*" %%a in ('dir %RECURSE% /b %~2') do (
        set DISPLAY_NAME=
        if "!COUNT!"=="%~3" (
                REM This next line has a trailing space.  The space is important
.
                set DISPLAY_NAME=^>
                set SELECTED=%%a
        ) else (
                REM This next line has trailing spaces.  The spaces are importan
t.
                set DISPLAY_NAME=
        )
        set DISPLAY_NAME=!DISPLAY_NAME!%%a
        set DISPLAY_NAME=!DISPLAY_NAME:%~1=!
        echo !DISPLAY_NAME!
        set /a COUNT=!COUNT!+1
)
popd
goto :eof

REM show_splash_screen
REM Displays the splash screen on the console.
:show_splash_screen
echo.
echo. File chooser brought to you by ^>indiv^<
echo.
for %%a in (1 2 3 4 5 6 7 8 9 a b c d e f) do ( color 0%%a )
color
goto :eof

REM pause_sec
REM Pause for the number of seconds given by ~1.
:pause_sec
set SECS=%1
if "%SECS%"=="" ( set SECS=1)
ping 127.0.0.1 -n %SECS% >NUL
goto :eof

Find all occurrences of "int" or "integer" in all files in a folder and replace with "long"


By : A.Loc
Date : March 29 2020, 07:55 AM
help you fix your problem I have a set of .xml files in a folder "model" with stuff like:
code :
find . -type f \( -name '*.xml' -o -name '*.java' \) \
  -exec sed -ri.back 's/\<int(eger)?\>/long/g' {} +
find . -type f \( -name '*.xml' -o -name '*.java' \) \
  -exec grep -ilZE '\<int(eger)\>' {} + |
  xargs -r0 sed -ri.back 's/\<int(eger)?\>/long/g'

Angularjs routing ejs static files in "views" folder from "public" folder of express.js


By : taiyang
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I just had to use app.set('views', path.join(__dirname, '/public')); to make ejs to lookup in publicdirectory rather than in views directory

Is there a os method to generate a dictonary=={"folder":[''sub_folder","file1","file2"


By : user2323330
Date : March 29 2020, 07:55 AM
With these it helps
code :
import os

def get_directory_structure(rootdir):
    """
    Creates a nested dictionary that represents the folder structure of rootdir
    """
    dir = {}
    rootdir = rootdir.rstrip(os.sep)
    start = rootdir.rfind(os.sep) + 1
    for path, dirs, files in os.walk(rootdir):
        folders = path[start:].split(os.sep)
        subdir = dict.fromkeys(files)
        parent = reduce(dict.get, folders[:-1], dir)
        parent[folders[-1]] = subdir
    return dir
{
    "root": {
        "folder2": {
            "item2": None, 
            "item1": None
        }, 
        "folder1": {
            "subfolder1": {
                "item2": None, 
                "item1": None
            }, 
            "subfolder2": {
                "item3": None
            }
        }
    }
}
shadow
Privacy Policy - Terms - Contact Us © soohba.com