Wazery
Wazery

Reputation: 15863

Command line to move the contents of an unnamed folder

I am trying to do a batch that fixes my flash drive from shortcut virus infection. I want to move the files from an unnamed folder (Alt+255) to the root directory of my flash drive, what is hard is that I can't do that with the short name of the folder because it is variable (one time it is 00A0~1 the other is 9DEC~1) so I am thinking of making a command that loops through the folders and prompts them to the user to decide if this is the unnammed folder or no like so (" " is that the folder? (Y/N)) similar to the output of this command:

for /d %d in (*) do rmdir /s "%d"

, but it moves all the contents of it to the root directory not delete it. How to do that?

Upvotes: 1

Views: 1181

Answers (3)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200193

You might be better off using VBScript or PowerShell for this instead.

VBScript:

Set fso = CreateObject("Scripting.FileSystemObject")

source     = "K:\"
quarantine = "C:\quarantine"

Set re = New RegExp
re.Pattern = "^[^a-z0-9_-]"
re.IgnoreCase = True

For Each fldr In fso.GetFolder(source).SubFolders
  If re.Test(fldr.Name) Then
    answer = MsgBox("Move " & fldr.Path & "'?", vbYesNo, "Folder Check")
    If answer = vbYes Then fldr.Move quarantine & "\"
  End If
Next

PowerShell:

$source     = "K:\"
$quarantine = "C:\quarantine"

Get-ChildItem $source -Force | ? {
  $_.PSIsContainer -and $_.Name -match '^[^a-z0-9_-]'
} | % {
  $answer = Read-Host "Move $($_.FullName)? [Y/n]"
  if ( $answer.Length -eq 0 -or $answer[0] -eq "y" ) {
    $_.MoveTo((Join-Path $quarantine $_.Name))
  }
}

Both solutions check the source folder for folder names not starting with an alphanumeric character, underscore, or hyphen, prompt the user, and (on confirmation) move that folder to the quarantine folder.

If you want to use the PowerShell version on Windows XP, you have to install the Windows Management Framework first. PowerShell is included with that package.

Upvotes: 1

foxidrive
foxidrive

Reputation: 41224

This may help:

@echo off
set "var="
for /f "delims=" %%a in ('dir /ad /b') do (
echo "%%a"
set /p "var=Is that it? press enter for no and Y for yes: "
  if defined var (
   attrib -h -s -r -a "%%a" /d
   move "%%a\*.*" \
 )
set "var="
)

Upvotes: 0

Endoro
Endoro

Reputation: 37569

This might work for you:

for /d %%i in (*) do echo %%~i |findstr "ECHO is" >nul&& move "%%~i" ELSEWHERE

This may move the folder   to ELSEWHERE.


for /d %%i in (*) do echo %%~i |findstr "ECHO is" >nul&& rd "%%~i" 

This may remove the folder .

Upvotes: 1

Related Questions