Create folders from txt file which need to be called

A

Artostapyshyn

Guest
Artostapyshyn Asks: Create folders from txt file which need to be called
I have problem with such task - Create folders from source.txt with names(could be with spaces) if folder haven't been creted write name in file Error.txt But it's not all :) file source.txt located in another folder. For example F:\Folder\source.txt and folders have to be created in F:\Folder\Fld1 I think the call command could be useful, but Idk how to use it. I tried call source.txt %~dp but it's useless when I'm moving to Fld1 to start for loop or just staying in Folder with source.txt

Here what I have so far(loop creating folders only in folder with source.txt but nowhere else)

Code:
for /F "delims== tokens=1,2" %G in (source.txt) do (
         md "%G" 
         if errorlevel 1 echo "%G" >> Error.txt

source.txt looks like:

Code:
Fold1
Fold2
Fold3
Fold4
Fold5
Fold6 
Fold Fold1
Fold Fold2
Fold Fold3
Fold Fold4
Fold Fold5
Fold Fold6

Thanks in advance!

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.
 
/forums/whats-new/news-feed

Unreplied Posts

Im trying to make a picker style like the appearance picker in settings

Ash Asks: Im trying to make a picker style like the appearance picker in settings
I'm tying to make a picker style that looks like this enter image description here

Here is the code for the theme

Code:
@main
struct GreenPowerPlantUniversalApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
                .modifier(DarkModeViewModifier())
        }
    }
    class AppThemeViewModel: ObservableObject {
        @AppStorage("appThemeSetting") var appThemeSetting = Appearance.system
    }
    
    struct DarkModeViewModifier: ViewModifier {
        @ObservedObject var appThemeViewModel: AppThemeViewModel = AppThemeViewModel()
        
        public func body(content: Content) -> some View {
            content
                .preferredColorScheme((appThemeViewModel.appThemeSetting == .system) ? .none : appThemeViewModel.appThemeSetting == .light ? .light : .dark)
        }
    }
    
    enum Appearance: String, CaseIterable, Identifiable  {
        case system
        case light
        case dark
        var id: String { self.rawValue }
    }
}
    struct ThemeSettingsView: View {
        @AppStorage("appThemeSetting") var appThemeSetting = GreenPowerPlantUniversalApp.Appearance.system
        
        var body: some View {
            VStack {
                    Picker("Appearance", selection: $appThemeSetting) {
                        ForEach(GreenPowerPlantUniversalApp.Appearance.allCases) { appearance in
                            Text(appearance.rawValue.capitalized)
                                .tag(appearance)
                        }
                    }
                    .pickerStyle(SegmentedPickerStyle())
            }.padding(.bottom, 100)
                .padding(.horizontal, 20)
        }
    }

I just don't know where to start to create this as I'm a beginner to swift.

I think it would be best to make a picker style which I don't know how to do but anything to create this would work

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

Blackjack Javascript problem dealer has 3 cards only needs to have 2

redmushroomrocket Asks: Blackjack Javascript problem dealer has 3 cards only needs to have 2
This is my first post. I'm new to coding and one of my projects is to create a simple version of Blackjack using Javascript. I made a basic website for it here and I've encountered a problem. The dealer occasionally gets dealt 3 or more cards. The dealer should always have 2 cards unless you hit or stay. Adding cards to the dealer like the player isn't required so I did not write code for it. I have the dealer sum limit set to 13 (I've tried lower/higher numbers, but that doesn't really "fix" the issue.") and also edited the for loops. I thought it could be an array problem. Perhaps I have the arrays too simplified and need to rename the cards?

Here is my code any help or tips would be appreciated!


Code:
var dealerSum = 0;
var yourSum = 0;


var dealerAceCount = 0;
var yourAceCount = 0;

var hidden;
var deck;

var canHit = true;

window.onload = function () {
    buildDeck()
    shuffleDeck()
    startGame()
}

function buildDeck() {
    let values = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"];
    let types = ["C", "D", "H", "S"]
    deck = []

    for (let i = 0; i < types.length; i++) {
        for (let j = 0; j < values.length; j++) {
            deck.push(values[j] + "-" + types[i]);
        }
    }
    // console.log(deck);
}


function shuffleDeck() {
    for (let i = 0; i < deck.length; i++) {
        let j = Math.floor(Math.random() * deck.length);
        let temp = deck[i];
        deck[i] = deck[j];
        deck[j] = temp;
    }
    // console.log(deck);
}

function startGame() {
    hidden = deck.pop();
    dealerSum += getValue(hidden);
    dealerAceCount += checkAce(hidden);
    // console.log(hidden);
    // console.log(dealerSum);

    while (dealerSum < 13) {
        let cardImg = document.createElement("img");
        let card = deck.pop();

        cardImg.src = "./cards/" + card + ".png";
        dealerSum += getValue(card);
        dealerAceCount += checkAce(card);
        document.getElementById("dealer-cards").append(cardImg);
    }
    console.log(dealerSum)

    for (let i = 0; i < 2; i++) {
        let cardImg = document.createElement("img");
        let card = deck.pop();
        cardImg.src = "./cards/" + card + ".png";
        yourSum += getValue(card);
        yourAceCount += checkAce(card);
        document.getElementById("your-cards").append(cardImg);


    }
    console.log(yourSum);
    document.getElementById("refresh").addEventListener("click", refresh);
    document.getElementById("hit").addEventListener("click", hit);
    document.getElementById("stay").addEventListener("click", stay);
}

function hit() {
    if (!canHit) {
        return;
    }
    let cardImg = document.createElement("img");
    let card = deck.pop();
    cardImg.src = "./cards/" + card + ".png";
    yourSum += getValue(card);
    yourAceCount += checkAce(card);
    document.getElementById("your-cards").append(cardImg);

    if (reduceAce(yourSum, yourAceCount) > 21) {
        canHit = false;
    }

}


function stay() {
    dealerSum = reduceAce(dealerSum, dealerAceCount);
    yourSum = reduceAce(yourSum, yourAceCount);

    canHit = false;
    document.getElementById("hidden").src = "./cards/" + hidden + ".png";

    let message = "";
    if (yourSum > 21) {
        message = "You lose! Better luck next time. Refresh to try again!"
    }
    else if (dealerSum > 21) {
        message = "You win! Refresh to play again!"
    }
    else if (yourSum == dealerSum) {
        message = "Tie! Refresh to play again!";
    }
    else if (yourSum > dealerSum) {
        message = "You win! Refresh to play again!";
    }
    else if (yourSum < dealerSum) {
        message = "You lose! Better luck next time. Refresh to play again!";
    }

    document.getElementById("dealer-sum").innerText = dealerSum;
    document.getElementById("your-sum").innerText = yourSum;
    document.getElementById("result").innerText = message;
}

function refresh() {
    window.location.reload();
}


function getValue(card) {
    let data = card.split("-");
    let value = data[0];

    if (isNaN(value)) {
        if (value == "A") {
            return 11;
        }
        return 10;
    }

    return parseInt(value);

}

function checkAce(card) {
    if (card[0] == "A") {
        return 1;
    }
    return 0;
}

function reduceAce(playerSum, playerAceCount) {
    while (playerSum > 21 && playerAceCount > 0) {
        playerSum -= 10;
        playerAceCount -= 1;
    }
    return playerSum;
}

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

Toast notifications do not work when user is in a different window

yryer Asks: Toast notifications do not work when user is in a different window
I am using making a cheat for minecraft, and I am using toast notifications to let the user know when it is toggled on or off. However, these notifications work in every app I've tried so far except minecraft. ToggleBtn_MouseDown is still called, but there is no notification. ToggleBtn_MouseDown is also called by a keyboard hook, if that is of relevance. Any ideas on why this is occuring?

Code:
 private async void ToggleBtn_MouseDown(object? sender, MouseButtonEventArgs? e)
        {
            await Task.Delay(20);
            if (ToggleBtn.Content.ToString() == "Enable")
            {
                ToggleBtn.Content = "Disable";
                clicker.Start();
            }
            else
            {
                ToggleBtn.Content = "Enable";
                clicker.Stop();
            }
            new ToastContentBuilder()
                .AddText($"1337 is {ToggleBtn.Content}d")
                .AddText("Disable these notifications in settings")
                .Show();
            await Task.Delay(1000);
            ToastNotificationManagerCompat.History.Clear();
        }

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

Flutter Bloc State Not Changing/ Updating

Ta-Ty Asks: Flutter Bloc State Not Changing/ Updating
I am new to blocs in Flutter and I am trying to use them to create, read, edit, and store user inputted data. I am currently using a bloc for my app's onboarding process. Ideally, once the user creates an account using Firebase email & password authentication, they will be prompted to answer a list of questions. The problem is, my state does not changing from loading to loaded. I have it set up to display a circular progress bar until it is loaded, then the text will appear, but there is no state change. I could really use some guidance or insight please :).

Main dart:

Code:
int? isViewed;
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  await FirebaseAppCheck.instance.activate();
  
  final prefs = await SharedPreferences.getInstance();
  final showLogin = prefs.getBool('showLogin') ?? false;
  Paint.enableDithering = true;
  
// This is for our onboarding screen
isViewed = prefs.getInt('onboard');

  runApp(MyApp(showLogin: showLogin));
}

class MyApp extends StatelessWidget {
  final bool showLogin;
  
  const MyApp({Key? key,
  required this.showLogin}) : super(key: key);


  @override
  Widget build(BuildContext context) {
    return MultiRepositoryProvider(
      providers: [
        RepositoryProvider(
          create: (context) => DatabaseRepository()
          ),
          RepositoryProvider(
            create: (context) => StorageRepository()
            )
      ],
      child: MultiBlocProvider(
        providers: [
          BlocProvider<OnboardingBloc>(
            create: (context) => OnboardingBloc(
              databaseRepository: context.read<DatabaseRepository>(),
              storageRepository: context.read<StorageRepository>()
            ))
        ],
          child: MaterialApp(
            title: 'Strength',
            debugShowCheckedModeBanner: false,
            initialRoute: AccountOnboarding.routeName, // Splash Screen
            routes: {
              '/splash screen' : (context) => const SplashScreen(),
              '/main onboarding' : (context) => const OnboardingScreen(),
              '/landing' : (context) => LandingScreen(),
              '/login' : (context) => const LoginScreen2(),
              '/dashboard' : (context) => const Dashboard(),
              '/profile onboarding' : (context) => const AccountOnboarding()
            },
            
            home: AccountOnboarding() // FINAL SCREEN IS SPLASH SCREEN
          )),
    );
      }
  }

Onboarding Bloc:

Code:
part 'onboarding_event.dart';
part 'onboarding_state.dart';

class OnboardingBloc extends Bloc<OnboardingEvent, OnboardingState> {
  final DatabaseRepository _databaseRepository;
  final StorageRepository _storageRepository;

  OnboardingBloc({
    required DatabaseRepository databaseRepository,
    required StorageRepository storageRepository,
  }) : 
  _databaseRepository = databaseRepository,
  _storageRepository = storageRepository,
  super(OnboardingLoading()) {
    on<StartOnboarding>(_onStartOnboarding);
    on<UpdateUser>(_onUpdateUser);
    on<UpdateUserImage>(_onUpdateUserImage);
  }

  void _onStartOnboarding(
    StartOnboarding event, 
    Emitter<OnboardingState> emit) 
    async {
      await _databaseRepository.createUser(event.user);
      emit(OnboardingLoaded(user: event.user));
    }

  void _onUpdateUser(
    UpdateUser event, 
    Emitter<OnboardingState> emit) {
      if (state is OnboardingLoaded) {
        _databaseRepository.UpdateUser(event.user);
        emit(OnboardingLoaded(user: event.user));
      }
    }

  void _onUpdateUserImage(
    UpdateUserImage event, 
    Emitter<OnboardingState> emit) 
    async{
      if (state is OnboardingLoaded) {
        User user = (state as OnboardingLoaded).user;

        await _storageRepository.uploadImage(user, event.image);

        _databaseRepository.getUser(user.id!).listen((user) {
          add(UpdateUser(user: user));
        });
      }
    }
}

Onboarding States:

Code:
part of 'onboarding_bloc.dart';

abstract class OnboardingState extends Equatable {
  const OnboardingState();

  @override
  List<Object> get props => [];
}

class OnboardingLoading extends OnboardingState {}

class OnboardingLoaded extends OnboardingState {
  final User user;

  OnboardingLoaded({required this.user});

  @override
  List<Object> get props => [user];
}

Onboarding Screen format:

Code:
class AccountOnboarding extends StatefulWidget {
  const AccountOnboarding({Key? key}) : super(key: key);
  static const String routeName = '/profile onboarding';

  static Route route() {
    return MaterialPageRoute(
      settings: const RouteSettings(name: routeName),
      builder: (context) => OnboardingScreen());
  }

  @override
  State<AccountOnboarding> createState() => _AccountOnboardingState();
  
}

class _AccountOnboardingState extends State<AccountOnboarding> {

    static const List<Tab> tabs = <Tab>[
    Tab(text: 'Name'),
    Tab(text: 'Age and Profile'),
    Tab(text: 'Bio and Interests'),
    Tab(text: 'Selection')
  ];

  @override
  Widget build(BuildContext context) {

    return DefaultTabController(
      length: tabs.length,
       child: Builder(builder: (BuildContext context) {
        final TabController tabController = DefaultTabController.of(context)!;
        tabController.addListener(() {
          if (!tabController.indexIsChanging) {}
        });
        return Scaffold(
          resizeToAvoidBottomInset: false,
          backgroundColor: const Color(0xff31708c),
          appBar: AppBar(
            automaticallyImplyLeading: false,
            backgroundColor: Colors.transparent,
            elevation: 0,
            title: Row(
              children: [
                Expanded(
                  child: Image.asset('assets/images/Logo_Strength.png',
                  height: 50),
                ),
                Expanded(
                  flex: 2,
                  child: RichText(
                              text: TextSpan(
                                style: GoogleFonts.montserrat(
                                  fontSize: 30),
                                  children: <TextSpan> [
                                    TextSpan(text: 'Stren', 
                                    style: GoogleFonts.montserrat(
                                      color: Colors.white, 
                                      fontWeight: FontWeight.bold, 
                                      letterSpacing: 1,
                                      shadows: [
                                        Shadow(
                                          color: Colors.black.withOpacity(0.7),
                                          offset: const Offset(1.5, 0.0))
                                      ])),
                
                                    TextSpan(text: ';', 
                                    style: GoogleFonts.montserrat(
                                      color: const Color(0xffef6a7a), fontWeight: FontWeight.bold, 
                                      letterSpacing: 1,
                                      shadows: [
                                        Shadow(
                                          color: Colors.black.withOpacity(0.7),
                                          offset: const Offset(1.5, 0.0))
                                      ])),
                
                                    TextSpan(text: 'th', 
                                    style: GoogleFonts.montserrat(
                                      color: Colors.white, 
                                      fontWeight: FontWeight.bold, 
                                      letterSpacing: 1,
                                      shadows: [
                                        Shadow(
                                          color: Colors.black.withOpacity(0.7),
                                          offset: const Offset(1.5, 0.0))
                                      ]))
                          ],
                        ),
                      ),
                ),
              ],
            )
        ),
        body: TabBarView(
          // physics: const NeverScrollableScrollPhysics(),
          children: [
            NamePage(tabController: tabController,),
            ageAndPicture(tabController: tabController,),
            bioAndInterests(tabController: tabController,),
            SelectionPage(tabController: tabController,)
          ],
        ),
        );
      }
    
  ));
}}

First onboarding screen (where states are addressed):

Code:
class NamePage extends StatelessWidget {
  final TabController tabController;

  const NamePage({Key? key,
  required this.tabController}) 
  : super(key: key);

  @override

  Widget build(BuildContext context) {
    double _height = MediaQuery.of(context).size.height;

    return BlocBuilder<OnboardingBloc, OnboardingState>(
      builder: (context, state) {
        if (state is OnboardingLoading) {
          return Center(
            child: CircularProgressIndicator(),
          );
        }

        if (state is OnboardingLoaded) {
        return Scaffold(
            resizeToAvoidBottomInset: false,
            backgroundColor: const Color(0xff31708c),
        
          body: Padding(
            padding: EdgeInsets.only(
              left: 30,
              right: 30,
              top: _height * 0.055,
              bottom: _height * 0.05),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Column(
                    children: [
                      Column(
                        children: <Widget>[
                          Text('Here at Strength, we respect your preferences. How would you like to be addressed?',
                          style: GoogleFonts.montserrat(
                            color: Colors.white,
                            fontSize: 19,
                            fontWeight: FontWeight.w600
                          ),
                          textAlign: TextAlign.center,),
                          Padding(
                            padding: EdgeInsets.only(
                              top: _height * 0.22),
                              child: SingleChildScrollView(
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: <Widget>[
                                    TextField(
                                      maxLength: 14,
                                      maxLengthEnforcement: MaxLengthEnforcement.enforced,
                                      onChanged: (value) {
                                        context.read<OnboardingBloc>()
                                        .add(UpdateUser(
                                          user: state.user.copyWith(name: value)));
                                      },
                                      cursorColor: Colors.white,
                                      style: GoogleFonts.montserrat(
                                        color: Colors.white,
                                        fontSize: 19,
                                        height: 2
                                      ),
                                      decoration: InputDecoration(
                                        enabledBorder: InputBorder.none,
                                        disabledBorder: InputBorder.none,
                                        focusedBorder: InputBorder.none,
                                        filled: true,
                                        helperText: 'Your name',
                                        helperStyle: GoogleFonts.montserrat(
                                          color: Colors.white,
                                          fontSize: 14.5,
                                          fontWeight: FontWeight.w600
                                        ),
                                        counterStyle: GoogleFonts.montserrat(
                                          fontSize: 14.5,
                                          fontWeight: FontWeight.w600
                                        ),
                                        // counterText: "",
                                        labelStyle: 
                                        GoogleFonts.montserrat(
                                          color: Colors.white,
                                          fontSize: 18),
                                        hintText: 'Please call me . . .',
                                        hintStyle: GoogleFonts.montserrat(
                                          color: Colors.white54,
                                          fontWeight: FontWeight.w600,
                                          fontSize: 18),
                                          border: InputBorder.none),
                                    ),
                                  ],
                                ),
                              ),),
                        ],
                      ),
                    ],
                  ),
                  Column(
                    children: [
                      Align(
                        alignment: 
                        Alignment.topLeft,
                        child: Text('1/4',
                        style: GoogleFonts.montserrat(
                          color: Colors.white,
                          fontWeight: FontWeight.w500
                        ),)),
                      const SizedBox(height: 5,),
                      const StepProgressIndicator(
                        totalSteps: 4, 
                        currentStep: 1,
                        roundedEdges: Radius.circular(20),
                        size: 3,
                        padding: 3,
                        selectedColor: Colors.white,
                        unselectedColor: Color.fromARGB(255, 20, 83, 106),),
                        const SizedBox(height: 13,),
                        CustomButton(tabController: tabController)
                    ],
                  ),
                ],
              ),
            ),
        );
      }
      else {
        return const Text('Something went wrong.');
      }
      }
    );
}
}

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

isin not working for searching a subset of columns for unique values

A Doe Asks: isin not working for searching a subset of columns for unique values
I have a data frame that have repetitions of some multiple column value combinations. I'm trying to extract the columns that have more than two repetitions. I have the following code

Code:
d = {'main_id': [1, 1, 1, 2, 2, 3, 3, 3], 'type': [1, 1, 1, 1, 1, 2, 2, 2], 'instant': [1, 2, 3, 1, 2, 1, 2, 3]}
df = pd.DataFrame(data=d)

uniqueCombinations = df.groupby(['main_id', 'type']).size().reset_index().rename(columns={0: 'Count'})
uniqueCombinations = uniqueCombinations.loc[uniqueCombinations['Count'] >= 3]
uniqueCombinations = uniqueCombinations.reset_index()
compare1 = df[['main_id', 'type']]
compare2 = uniqueCombinations[['main_id', 'type']]
mask = (compare1.isin(compare2)).all(axis=1)

What I do is to extract the rows that have [1,1] and [3,2] in the main_id and type columns in the df data frame. It's only matching only one row. Where am I doing wrong?

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

Latest posts

Top